How to plot troughs


_SECTION_BEGIN("TroughPlot");

//Trough Dates and Prices

Change = 10;
TroughDate = Ref(DateTime(), -TroughBars(C,Change,1)); 
Trough1 =( Trough(Close,Change,1) ); 

P = ParamField("Price field",-1);
MA10 = ( MA( P,15 )); 

Buy  = Cross(C,MA10);   
Sell = Cross(MA10,C);

Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
                 
PlotShapes(Ref(TroughDate,1), shapeHollowSquare,  shapeNone),colorwhite,  0,L, Offset= -60);     

 
_SECTION_END();

/*  
The above code is intended to print a shapeHollowSquare on the bar for events of TroughDate1 but returns an error so the syntax is incorrect
How can this code be corrected to achieve its aim.
I promise to try each suggestion and reply with my findings. 
*/

There are syntax errors in your code, and a lot of () brackets that aren't required.

See, TroughDate and Trough1 aren't events so you can't just use them in the Plotshapes() fn.

Anyway, check the code below if it serves the purpose.

I've used a very small change value according to my TF but this seems to do it.
Use small values of Change and go up else you might not have any plots.

Change = 0.5;
TroughDate = Ref(DateTime(), -TroughBars(C,Change,1)); 
Trough1 = Trough( Close, Change, 1); 

P = ParamField("Price field",-1);
MA10 = MA( P,15 ); 

Buy  = Cross( C, MA10);   
Sell = Cross( MA10, C);

Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Plot( C, "", colorDefault, styleBar );                 
PlotShapes( IIf( C == Trough1, shapeHollowSquare, shapeNone ),colorwhite,  0,L, Offset= -60);     

/*
Thank you travick,
I applied your suggestion and it works fine. I will now proceed and apply it to a more substantial code and hopefully achieve similar outcome.
But I don't understand what is meant by TroughDate and Trough1 not being events. Do I therefore assume it is because they are created by me and not typical arrays such as in C, H, O and L.
Also, I deleted "Plot( C, "", colorDefault, styleBar );" and the code still appears to work the same.
Was that included for a particular reason?.

Thanks Keith */