I am trying to piece together an EA based on the cashbackforex site.

I have got the basics running, but am having an issue trying to add the trailing stop and money management codes.

Can someone take a look and tell me why the attributes will not work? If I scratch the MM codes, then the least the EA works, but the trailing stop still does not function. Together with the MM code active, it will not even start any transactions.

Thanks in advance.



Inserted Code // Section 1: // Preprocessor Directives, External Internal Variables #property copyright Copyright © 2008-2010, ForexRazor.Com #property link http://www.forexrazor.com/ //----------------------- EA PARAMETER extern string Expert_Name = ---------- STOCHcross; extern double MagicNumber = 59483; extern string MM_Parameters = ---------- Money Management; extern double Lots = 1; extern bool MM = false, //Use Money Management or not FromBalance = false; //Use Balance instead of Margin extern int Risk = 10; //10% extern string Order_Setting = ---------- Order Setting; extern bool OppositeClose = true; extern bool EnterOpenBar = true; extern double TakeProfit =100; extern double StopLoss = 75; extern string TrailingStop_Setting = ---------- Trailing Stop Setting; extern double TrailingStart = 50; extern double TrailingStop = 25; extern double TrailingStep = 5; extern string Indior_Setting = ---------- Indior Setting; extern int KPeriod = 14, DPeriod = 4, Slowing = 5; extern double UnderSoldLevel = 30, OverBoughtLevel = 70; extern int Slippage = 5; // Global Variables int Counter, vSlippage; double ticket, number, vPoint; double sl, tp; double kline#91;3#93;, dline#91;3#93;; bool crossedup, crosseddown; int longtkt, shorttkt, cnt, t; // Section 2: Initialization int init() //------------------------------------------------------- // Section 3: Start int start() crossedup = false; crosseddown = false; if(Barslt;100) Print(Bars less than 100); return(0); //-------------------------------------------------------- // Section 3A: Define ShortCuts to Common Functions int Total, OType=-1, Ticket; double Price, SL, TP, Lot; bool CloseBuy=false, CloseSell=false, OpenBuy=false, OpenSell=false; for(int Counter=1; Counterlt;=OrdersTotal(); Counter ) if (OrderSelect(Counter-1,SELECT_BY_POS)==true) if (OrderSymbol() == Symbol() OrderMagicNumber() == MagicNumber) Ticket=OrderTicket(); OType =OrderType(); Price =OrderOpenPrice(); SL =OrderStopLoss(); TP =OrderTakeProfit(); Lot =OrderLots(); //---------------------------------------------------- // Section 3B: Indior Calling for(int I = 0;I lt; 3;I ) kline#91;I#93; = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA, 0, MODE_MAIN, I); dline#91;I#93; = iStochastic(NULL, Period(), KPeriod, DPeriod, Slowing, MODE_SMA, 0, MODE_SIGNAL, I); if ((kline#91;1#93; lt; dline#91;1#93;-RRB- (kline#91;2#93; gt; dline#91;2#93;-RRB-) crosseddown = true; else if ((kline#91;1#93; gt; dline#91;1#93;-RRB- (kline#91;2#93; lt; dline#91;2#93;-RRB-) crossedup = true; else return(0); //------------------------------------------------ // Section 3C: Entry Conditions bool OpenBar=true; if(EnterOpenBar) if(iVolume(NULL,0,0)gt;1) OpenBar=false; if (crossedup (kline#91;1#93; lt; UnderSoldLevel) OpenBar) OpenBuy=true; if (OppositeClose) CloseSell=true; if (crosseddown (kline#91;1#93; gt; OverBoughtLevel) OpenBar) OpenSell=true; if (OppositeClose) CloseBuy=true; //------------------------------------------------- // Section 3D: Close Conditions while(true) if (OType==0 CloseBuy==true) close (OP_BUY); // Close Buy return; if (OType==1 CloseSell==true) close (OP_SELL); // Close Sell return; break; //-------------------------------------------------- // Section 3E: Order Placement while(true) if (OrdersTotalMagicOpen()==0 OpenBuy==true) if(StopLossgt;0)SL=Ask - StopLoss*vPoint;elseSL=0; if(TakeProfitgt;0)TP=Ask TakeProfit*vPoint;elseTP=0; ticket=0;number=0; while(ticketlt;=0 numberlt;100) RefreshRates(); ticket = OrderSend(Symbol(),OP_BUY, Lots, Ask,vSlippage,SL,TP,Expert_Name, MagicNumber, 0, Green); return (ticket); if (OrdersTotalMagicOpen()==0 OpenSell==true) if(StopLossgt;0)SL=Bid StopLoss*vPoint;elseSL=0; if(TakeProfitgt;0)TP=Bid-TakeProfit*vPoint;elseTP=0; ticket=0;number=0; while(ticketlt;=0 numberlt;100) RefreshRates(); ticket= OrderSend(Symbol(),OP_SELL, Lots, Bid,vSlippage,SL,TP, Expert_Name, MagicNumber, 0, Red); return (ticket); break; //--------------------------------------------------------- return; // End of start() // Section 4A: Close Function void OnTick() if(MM)CalculateMM(); void close(int type) if(OrdersTotal()gt;0) for(Counter=OrdersTotal()-1;Countergt;=0;Counter--) OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES); if(type==OP_BUY OrderType()==OP_BUY) if(OrderSymbol()==Symbol() OrderMagicNumber()==MagicNumber) RefreshRates(); OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Bid,Digits), vSlippage); if(type==OP_SELL OrderType()==OP_SELL) if(OrderSymbol()==Symbol() OrderMagicNumber()==MagicNumber) RefreshRates(); OrderClose(OrderTicket(),OrderLots(),NormalizeDoub le(Ask,Digits),vSlippage); // Section 4B: OrdersTotalMagicOpen Function int OrdersTotalMagicOpen() int l_count_0 = 0; for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 gt;= 0; l_pos_4--) return (l_count_0); void TrailOrder(double Trailingstart,double Trailingstop) int ticket = 0; double tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Reduction int cnt,vPoint,vSlippage; double sl = OrderStopLoss(); // Stop Reduction RefreshRates(); if(OrdersTotal()gt;0) for(cnt=OrdersTotal();cntgt;=0;cnt--) OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()lt;=OP_SELL OrderSymbol()==Symbol() OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUY) if(Askgt; NormalizeDouble(OrderOpenPrice() TrailingStart* vPoint,Digits) tStopLoss lt; NormalizeDouble(Bid-(TrailingStop TrailingStep)*vPoint,Digits)) tStopLoss = NormalizeDouble(Bid-TrailingStop*vPoint,Digits); ticket = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLo ss,OrderTakeProfit(),0,Blue); if (ticket gt; 0) Print (TrailingStop #2 Activated:, OrderSymbol(),: SL, tStopLoss,: Bid, Bid); return(0); if (OrderType()==OP_SELL) (OrderStopLoss()==0)) tStopLoss = NormalizeDouble(Ask TrailingStop*vPoint,Digits); ticket = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLo ss,OrderTakeProfit(),0,Red); if (ticket gt; 0) Print (Trailing #2 Activated:, OrderSymbol(),: SL,tStopLoss,: Ask, Ask); return(0); //----------------------- MONEY MANAGEMENT FUNCTION void CalculateMM() double MinLots=MarketInfo(Symbol(),MODE_MINLOT); double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT); if(FromBalance==false) Lots=AccountFreeMargin()/100000*Risk; else if(FromBalance==true) Lots=AccountBalance()/100000*Risk; Lots=MathMin(MaxLots,MathMax(MinLots,Lots)); if(MinLotslt;0.1)Lots=NormalizeDouble(Lots,2); else if(MinLotslt;1)Lots=NormalizeDouble(Lots,1); else Lots=NormalizeDouble(Lots,0); if(Lotslt;MinLots)Lots=MinLots; if(Lotsgt;MaxLots)Lots=MaxLots; https://forexintuitive.com/attachmen...5371226498.mq4