Download MetaTrader 5

Help with Adjust SL and Trailing..Invalid Stops?

To add comments, please log in or register
Deposit to your account via PayPal
rooster44
157
rooster44 2012.01.30 06:38 

Hello all,

I have 2 problems right now, one has to do with my Adjust_SL_AP parameter which when true adjusts the SL to the average price of the trade when scaling in... should i be using Positiongetdouble(POSITION_CURRENT_PRICE)?

Next when Adjust_SL_AP is false it should be using a trailing stop loss, but it does not seem to be working.

Thank you!

// trailing and Sl
        if(PositionSelect(S[I]))           {
        
        double gi_avpriceb = SymbolInfoDouble(S[I],SYMBOL_BID) - PositionGetDouble(POSITION_PRICE_CURRENT);
        double gi_avprices = PositionGetDouble(POSITION_PRICE_CURRENT) - SymbolInfoDouble(S[I],SYMBOL_ASK);  
           if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
               { 
                if ( PositionGetDouble(POSITION_VOLUME)==gs_lots && PositionGetDouble(POSITION_PRICE_OPEN) - SymbolInfoDouble(S[I], SYMBOL_ASK) > First_SL*gi_point   )  sell(gs_lots) ;         
                  if(ss==1)trX.PositionClose(S[I],100);
                  if ( Adjust_SL_AP ) { if((PositionGetDouble(POSITION_PRICE_CURRENT)<SymbolInfoDouble(S[I], SYMBOL_BID)&&PositionGetDouble(POSITION_PROFIT)>0) && (PositionGetDouble(POSITION_SL)<SymbolInfoDouble(S[I], SYMBOL_BID) - gi_avpriceb || PositionGetDouble(POSITION_SL)==0));
                             trX.PositionModify(S[I],SymbolInfoDouble(S[I], SYMBOL_BID)-gi_avpriceb,PositionGetDouble(POSITION_TP)); }
                  else { if(Trailing>0&&SymbolInfoDouble(S[I], SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN) > gi_point*Trailing&& (PositionGetDouble(POSITION_SL)<SymbolInfoDouble(S[I], SYMBOL_BID) - gi_point*(Trailing+5) || PositionGetDouble(POSITION_SL)==0));
                             trX.PositionModify(S[I],SymbolInfoDouble(S[I], SYMBOL_BID) - gi_point*Trailing,PositionGetDouble(POSITION_TP)); }
               }
           if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
               { 
                if ( PositionGetDouble(POSITION_VOLUME)==gs_lots && SymbolInfoDouble(S[I], SYMBOL_ASK) - PositionGetDouble(POSITION_PRICE_OPEN)  > First_SL*gi_point   ) buy(gs_lots) ;         
                  if(ss==2)trX.PositionClose(S[I],100);
                  if ( Adjust_SL_AP ) { if((PositionGetDouble(POSITION_PRICE_CURRENT)<SymbolInfoDouble(S[I], SYMBOL_BID)&&PositionGetDouble(POSITION_PROFIT)>0)&& (PositionGetDouble(POSITION_SL)>SymbolInfoDouble(S[I], SYMBOL_ASK) + gi_avprices || PositionGetDouble(POSITION_SL)==0));
                             trX.PositionModify(S[I],SymbolInfoDouble(S[I], SYMBOL_ASK)+gi_avprices,PositionGetDouble(POSITION_TP)); }
                  else { if(Trailing>0&&PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(S[I], SYMBOL_ASK) > gi_point*Trailing && (PositionGetDouble(POSITION_SL)>SymbolInfoDouble(S[I], SYMBOL_ASK) + gi_point*(Trailing+5) || PositionGetDouble(POSITION_SL)==0))
                             trX.PositionModify(S[I],SymbolInfoDouble(S[I], SYMBOL_ASK) + gi_point*Trailing,PositionGetDouble(POSITION_TP)); }
               }
           
         }
   

      }
Documentation on MQL5: Trade Functions / PositionGetDouble
  • www.mql5.com
Trade Functions / PositionGetDouble - Documentation on MQL5
To add comments, please log in or register