Need help with script Help.....

 

Hi all how is it going? I have a script I need help with. what I want to add is a trailing stop input to this script like T.P. & S.l. in the code. Also an input for a lock in pipes so if I have an open trade & I set my trailing stop at say fifteen & made the market doesn't reach the trailing stop and reverses I want to lock in say five pips. I have a buy sell & quick reversal scripts if someone can do one that i can figure out the code for the others. These should be profitable if set right.

Thanks in advance,

Mike

turbotrader24

Files:
Scripts.zip  24 kb
 

Here is the buy code that I need modified like explained on post 1.

Thank you

Mike

//+-------------------------------------------------------------------------+

//| IBFX - Quick Buy.mq4 |

//+-------------------------------------------------------------------------+

//----

int start()

{

/*+-------------------------------------------------------------------------+

Because these scripts are meant to execute fast there are no user

external inputs. Make sure to modify the settings below, then compile

the script before assigning a hot key to it and using it.

The magicNumber HAS TO TO BE THE SAME ON ALL SCRIPTS if you change it

here make sure to change it on all scripts!!!

Do not forget to click on COMPILE once your changes have been made!!!

+-------------------------------------------------------------------------+*/

int MagicNumber = 901;

double Risk = 2.0;

int StopLoss = 0; // Number in Pips ie: 50 for 50 pips.

int ProfitTarget = 5; // Number in Pips ie: 50 for 50 pips.

int Slippage = 1;

bool MiniLots = True; // Does your broker offer mini micro lots such as 0.01 lot?

string Commentary = " IBFX - Quick Buy ";

string FontName = "Arial";

int FontSize = 12;

//+-------------------------------------------------------------------------+

//| DO NOT MODIFY ANYTHING BELOW THIS LINE!!! |

//+-------------------------------------------------------------------------+

//---- A few checks before we get started

if( !IsConnected() ) { Alert( Commentary + " - No Connection!!" ); return(0); }

//---- Specific Vars

int Action = OP_BUY;

double InitPrice = Ask;

//---- Global Vars

bool Done = False;

string Symbole = Symbol();

int Ticket = 0;

int ErrorCode = 0;

double MaxLots = MarketInfo( Symbole, MODE_MAXLOT );

double Lots =MM( Symbole, Risk, MiniLots );

//---- Let's place the order.

while( !Done )

{

double FillPrice = Ask;

double StopPrice = Bid;

if( MathAbs( InitPrice - FillPrice ) > Slippage * Point ) { Done = true; }

Comment( "IBFX - QuickBuy | Placing Long Order, please wait ..." );

Wait();

Ticket = OrderSend( Symbole, Action, Lots, FillPrice, Slippage * Point, StopLong( StopPrice, StopLoss ), TakeLong(FillPrice, ProfitTarget), Commentary, MagicNumber, 0, CLR_NONE );

if( Ticket >= 0 ) { Done = true; }

else

{

ErrorCode = GetLastError();

if( ErrorCode == 4109 ) { Alert( Commentary + " - You did not allow live trading!" ); Done = true; }

else if( ErrorCode == 134 ) { Alert( Commentary + " - Not enough Money!" ); Done = true; }

else if( ErrorCode == 138 || ErrorCode == 136 || ErrorCode == 135 ) { Alert( Commentary + " - Requote/Slippage, run the script again" ); Done = true; }

else { Alert( Commentary + " Error: " + ErrorCode ); }

}

}

Comment("");

//----

return(0);

}

//+-------------------------------------------------------------------------+

//+-------------------------------------------------------------------------+

//+ Wait +

//+-------------------------------------------------------------------------+

void Wait() { while( IsTradeContextBusy() ) { Sleep(50); } }

//+-------------------------------------------------------------------------+

//+-------------------------------------------------------------------------+

//| Calculate Stop Short |

//+-------------------------------------------------------------------------+

double StopLong(double price,int stop)

{

if(stop==0) { return(0); }

else { return(price-(stop*Point)); }

}

//+-------------------------------------------------------------------------+

//| Calculate Profit Target Long |

//+-------------------------------------------------------------------------+

double TakeLong(double price,int take)

{

if(take==0) { return(0);}

else { return(price+(take*Point));}

}

//+-------------------------------------------------------------------------+

//+-------------------------------------------------------------------------+

//| Money Managment |

//+-------------------------------------------------------------------------+

double MM( string Sym, double Risk, bool BrokerAllowsFractionalLots )

{

double MinLots = MarketInfo(Sym,MODE_MINLOT);

double MaxLots = MarketInfo(Sym,MODE_MAXLOT);

double Leverage = AccountLeverage();

double LotSize = MarketInfo(Sym,MODE_LOTSIZE);

double LotStep = MarketInfo(Sym,MODE_LOTSTEP);

double FinalAccountBalance = MathMin( AccountBalance(), AccountEquity() );

int NormalizationFactor = 0;

double Lots = 0.0;

if(LotStep == 0.01) { NormalizationFactor = 2; }

if(LotStep == 0.1) { NormalizationFactor = 1; }

if( BrokerAllowsFractionalLots == true)

{

Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);

Lots = StrToDouble(DoubleToStr(Lots, NormalizationFactor));

if (Lots < MinLots) { Lots = MinLots; }

if (Lots > MaxLots) { Lots = MaxLots; }

}

else if(BrokerAllowsFractionalLots == false)

{

Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);

Lots = MathRound(Lots);

if (Lots < MinLots) { Lots = MinLots; }

if (Lots > MaxLots) { Lots = MaxLots; }

}

return( Lots );

}