and save it until a higher closing price is achieved?
eg: prev candle's closing price is 1.0950, which is saved as a variable. I want to save this price until a candle shows a higher closing price, in which case, the new closing price wil be the value of my variable.
If I try to set the closing price as a static, it gets saved, but then i cant replace it with a new value.
If I try to set it as a double, it gets saved only for the duration of that bar, and changes with each bar.
save it as a global variable (double).
then do something like
bar_close=Close;// save new high.
Try this example:
// Rates Structure for the data of the Last complete BAR
CopyRates(Symbol(), Period(), 1, 1, BarData); // Copy the data of last complete BAR
// Highest value of the CLOSE price.
static double dMy_Highest_Close_Price = 0; // Use a static double to keep the value in the memory or use a global variable.
// Check of new close price is higher than the saved close price.
if(BarData.close > dMy_Highest_Close_Price)
dMy_Highest_Close_Price = BarData.close; // Update the new highest close price.
Print("My highest close price = ", dMy_Highest_Close_Price, " Current close price = ", BarData.close);