The future M structure
Advance Trailing Stop
https://www.youtube.com/watch?v=VL1_NGaAOaU
https://www.youtube.com/watch?v=T78Q7K3c11s
//include the file Trade.mqh
#include<Trade\Trade.mqh>
// Create an instance of CTrade
Ctrade trade;
void onTick()
{
// Get the ask price
double Ask = NormalizeDouble(Symbol, SYMBOL_ASK), _Digits);
}
if (PositionsTotal()<2)
//Open 2 test buy positions
trade.Buy(0.10,NULL,Ask-1000*_Point),(Ask+500 * _Point), NULL);
//Call the Trailing Stop Module
CheckTrailingStop(Ask);
} //End of the OnTick function
void CheckTrailingStop(double Ask)
{
//set the desired stop Loss to 150 Points
double SL = NormalizeDouble(Ask - 150 * _Poin, _Digits);
//check all open positions for the current symbol
for(int i = PositionsTotal() - 1; i >= 0; i--) //count all currency pair positions
{
string symbol = PositionGetSymbol(i); //count all currency pair positions
if (_symbol == symbol) // if chart symbol equals position symbol
{
//get the ticket number
ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
//get the current stop loss
double CurrentStopLoss = PositiongetDouble(POSITION_SL);
// If Current Stop Loss is below 150 points from Ask price
if (CurrentStopLoss < SL)
{
//Modify the Stop Loss by 10 points
trade.PositionModify(PositionTicket, (CurrentStopLoss + 10 * _Point), 0);
}
} // End of symbol if decision
}// End of for loop
}//End of Trailing Stop function