//+-------------------+ //| 1MA Expert | //+-------------------+ #property copyright "Ron Thompson" #property link "http://www.lightpatch.com/forex" // User Input extern double Lots = 0.1; extern double stoploss=22; extern double takeprofit=35; // // make sure to leave this unset // It triggers the 1st buy. // // Also, define here so it has global scope // at least, within this expert // int prevTime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //|------------------------------------------------------------------| int init() { return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double MovingAvg = 10; double cMA=0, pMA=0; double p=Point(); bool found=false; bool rising=false; bool falling=false; bool bought=false; bool sold=false; int cnt=0; int err=0; double oop=0; //order open price double osl=0; //order stop loss double ccl=0; //current close price int rty=0; // Only compute right after each bar move // but check for BreakEven adjust each tick // // RISK MITIGATION // Set stoploss to orderprice (break-even) if price is // at least OpenPrice+StopLoss on close[0], but only // do it ONE TIME, controlled by oop>osl(buy) ooposl && ccl>(oop+(stoploss*p)) ) { // One-time move to break even // try up to ten times in case of error for (rty=1; rty<=10; rty++) { OrderModify(OrderTicket(),OrderOpenPrice(),oop,OrderTakeProfit(),0,Red); if(GetLastError()==0) { Print(Symbol()," BOUGHT One time break-even adjustment to ", oop); break; } else { Print(Symbol()," BOUGHT Break-Even modify Error=", err, " LOOP=",rty, " Time=",Time[0]); Sleep(10000); } } } } if (sold) { if (oopcMA) {rising=false; falling=true;} // Does the Symbol() have an open order for(cnt=0;cnt