Need help with an addition to my code
Results 1 to 2 of 2

Thread: Need help with an addition to my code

  1. #1
    Could someone please add the following to my own code? I will provide you the EA for performing this

    changeable 1

    1a after X quantity of grid trades, increase grid dimensions by X variable
    1b and the same quantity of X transactions as a, increase lot size by X variable (rather than master or the original variable )

    variable 2

    2a (after the first increase), after X quantity of grid trades, increase grid dimensions by X variable
    2b and the identical amount of X transactions as a, increase lot size by X variable (rather than the 1st adjusted variable above this )

    variable 3

    31 (after the next increase), after X quantity of grid trades, increase grid dimensions by X variable
    3b also after the same quantity of X transactions as a, increase lot size by X variable (rather than the 2nd adjusted variable above this )

    Maximum cash loss = X


    if you're able to figure out how to get this done in a different save, I would be impressed

    1)
    open x buy
    open x short

    two )
    if price moves in the amount of the grid, market all in profit positions, and open another position WITH TREND (the same sort of position that just cashed out) in an X variable of the first long position.

    This means if I cash out 1 after the grid increases 10 pips, I'll open up 1.5 longs (if the X variable has been corrected by me personally to be set to 1.5)

    also if prices goes to the sum the grid is set at, recovery position = X variable
    (pretty standard for a grid EA)




    THIS IS THE DEFAULT CODE (not the configurations I use for your EA however )

    //--
    extern series GRID = -- Grid Settings --
    extern int MaxOrders = 10;
    extern double GridDistance = 50;
    extern double PipProfitTarget = 10;
    extern double $$ProfitTarget = 200;
    extern double LotMultipler = 1.5;
    extern double Emergencystop = 1000;

    extern series TRAD = -- Trading Condition Settings --;
    extern int UniqeID = 200;
    extern series FirstOpenType = buy;
    extern double OpenLot = 0.1;
    extern double TakeProfit = 100;
    extern series EAName = CL-Martingale Base;
    extern bool ScreenDisplay = true;

    int dig, opentrades, lastticket, lastindex, lastopentype, count;
    double pnt, totalpipPL, totaldollarPL;
    series EAComment;
    int OpenTicket[100];
    int MagicNumber[100];
    double OpenPrice[100];
    double OpenLots[100];

    // ------------------------------------------------------------------
    //| INITIALIZATION |
    // ------------------------------------------------------------------
    int init() dig==5)
    pnt*=10;

    //--
    EAComment=EAName , Symbol() Period();
    ArrayResize(OpenTicket,MaxOrders);
    ArrayResize(MagicNumber,MaxOrders);
    ArrayResize(OpenPrice,MaxOrders);
    ArrayResize(OpenLots,MaxOrders);

    countprimarytrades();
    if (OpenTicket[0]! ) =0)
    if (OrderSelect(OpenTicket[0],SELECT_BY_TICKET))
    if (OrderType()==OP_BUY) lastopentype=0;
    else lastopentype=1;


    else
    if (FirstOpenType==buy) lastopentype=1;
    else if (FirstOpenType==market ) lastopentype=0;

    //--
    return(0);


    // ------------------------------------------------------------------
    //| DEINITIALIZATION |
    // ------------------------------------------------------------------
    int deinit()
    //--
    Comment();
    //--
    return(0);


    // ------------------------------------------------------------------
    //| MAIN LOOP |
    // ------------------------------------------------------------------
    int start()
    //--
    counttrades();
    if (opentrades! ) =0)
    if (nextrecovery()) opennext_R(lastindex 1);
    if (lastindexgt;0) totalclose();

    countprimarytrades();
    if (count==0) openprimaytrade();
    if (ScreenDisplay) checkcomment();
    //--
    return(0);


    //************************************************** ************************************************** **
    //************************************************** ************************************************** **

    // ------------------------------------------------------------------
    //| FUNCTIONS: Counting Trades |
    // ------------------------------------------------------------------
    void assigndata(int r)
    //--
    OpenTicket[r]=OrderTicket();
    OpenPrice[r]=OrderOpenPrice();
    OpenLots[r]=OrderLots();
    MagicNumber[r]=OrderMagicNumber();


    void deletedata(int r)
    //--
    OpenTicket[r]=0;
    OpenPrice[r]=0;
    OpenLots[r]=0;
    MagicNumber[r]=0;


    void counttrades()
    //--
    int total=OrdersTotal();
    lastticket=0;
    lastindex=0;
    opentrades=0;

    if (total==0) opentrades=0;
    else
    for (int I=0; ilt;overall; I )
    if (! OrderSelect(i,SELECT_BY_POS)) continue;
    if (OrderSymbol()! =Symbol()) continue;
    if ((OrderMagicNumber()-UniqeID)gt;=0 (OrderMagicNumber()-UniqeID)lt;MaxOrders)
    opentrades ;
    lastticket=OrderTicket();
    lastindex=OrderMagicNumber()-UniqeID;
    assigndata(lastindex);





    void countprimarytrades()
    //--
    int total=OrdersTotal();
    count=0;

    deletedata(0);
    if (total! =0)
    for (int I=0; ilt;total; I )
    if (! OrderSelect(i,SELECT_BY_POS)) continue;
    if (OrderSymbol()! =Symbol()) continue;
    if (OrderMagicNumber()==UniqeID)
    OpenPrice[0]=OrderOpenPrice();
    assigndata(0);
    count ;





    // ------------------------------------------------------------------
    //| FUNCTION: Retrieval |
    // ------------------------------------------------------------------
    bool nextrecovery()
    //--
    if (OrderSelect(lastticket,SELECT_BY_TICKET))
    if (OrderType()==OP_BUY)
    double price=OrderOpenPrice()-GridDistance*pnt;
    if (Asklt;=price) return (true);
    else return (false);


    else if (OrderType()==OP_SELL)
    price=OrderOpenPrice() GridDistance*pnt;
    if (Bidgt;=price) return (true);
    else return (false);

    else return (false);



    void opennext_R(int r)
    //--
    if (OrderSelect(lastticket,SELECT_BY_TICKET))
    if (OrderType()==OP_BUY) opentrade(r,0);
    else if (OrderType()==OP_SELL) opentrade(r,1);

    if (r==MaxOrders-1) Alert (Max number of transactions reached!) ;



    void totalclose() (totalpipPLgt;=PipProfitTarget)

    // ------------------------------------------------------------------
    //| FUNCTIONS: Order Excution |
    // ------------------------------------------------------------------
    void openprimaytrade()
    //--
    if (lastopentype==OP_BUY) opentrade(0,1);
    else if (lastopentype==OP_SELL) opentrade(0,0);


    void opentrade(int r,int type) {
    //--
    int magicnumber=UniqeID r;
    series identifier, ordertype;
    double price, stoploss, takeprofit;

    if (r==0) identifier= Main;
    else identifier= Recovery;
    if (r==0) double lot=normalizelot(OpenLot);
    else if (rgt;0 rlt;MaxOrders) lot=normalizelot(MathPow(LotMultipler,r)*OpenLot);

    if (type==OP_BUY)
    price=Ask;
    ordertype= BUY;

    else if (type==OP_SELL)
    price=Bid;
    ordertype= SELL;


    int ticket=OrderSend(Symbol(),type,lot,price,0,0,0,EAC omment,magicnumber,0,Lime);<br /P if(ticketgt;0)
    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) identifier ordertype order Started: @ DoubleToStr(OrderOpenPrice(),dig));

    if ((r==0) (type==OP_BUY))
    lastopentype=0;
    //if (StopLoss! ) =0) stoploss=OrderOpenPrice()-StopLoss*pnt;
    //else stoploss=0;
    if (TakeProfit! ) =0) takeprofit=OrderOpenPrice() TakeProfit*pnt;
    else takeprofit=0;

    else if ((r==0) (type==OP_SELL))
    lastopentype=1;
    //if (StopLoss! ) =0) stoploss=OrderOpenPrice() StopLoss*pnt;
    //else stoploss=0;
    if (TakeProfit! ) =0) takeprofit=OrderOpenPrice()-TakeProfit*pnt;
    else takeprofit=0;

    if (takeprofit! ) =0)
    OrderModify(ticket,OrderOpenPrice(),0,takeprofit,0 ,CLR_NONE);


    else TIME_SECONDS)
    }

    emptiness closetrade()
    //--
    double price;

    if (OrderType()==OP_BUY) price=Bid;
    else if (OrderType()==OP_SELL) price=Ask;

    bool result=OrderClose(OrderTicket(),OrderLots(),price, 1,MediumSeaGreen);
    if (result) EAComment
    if (! Result) TIME_SECONDS)


    dual normalizelot(double size)
    //--
    if (MarketInfo(Symbol(),MODE_LOTSTEP)==0.01) int digit=2;
    else if (MarketInfo(Symbol(),MODE_LOTSTEP)==0.1) digit=1;
    else digit=0;

    double val=NormalizeDouble(size( digit);
    if (vallt;MarketInfo(Symbol(),MODE_MINLOT)) val=MarketInfo(Symbol(),MODE_MINLOT);
    else if (valgt;MarketInfo(Symbol(),MODE_MAXLOT)) val=MarketInfo(Symbol(),MODE_MAXLOT);
    //--
    return(val);


    // ------------------------------------------------------------------
    //| FUNCTION: Miscellaneous |
    // ------------------------------------------------------------------
    emptiness checkcomment()
    //--
    chain com;
    for (int r=0; rlt;MaxOrders; r )
    if (OpenTicket[r]! =0)
    series compr=\n-- ( DoubleToStr(r,0) ) trade ticket: DoubleToStr(OpenTicket[r],0) , open price: DoubleToStr(OpenPrice[r],Digits) , order lots: Factory DoubleToStr(OpenLots[r],2);
    Id =com compr;



    if (totaldollarPL==0) series a=X;
    else a=DoubleToStr(totaldollarPL,2);
    if (totalpipPL==0) series b=X;
    else b=DoubleToStr(totalpipPL,1);
    Comment(\n-----------------------------
    \n-- General profit in $$: a
    \n-- General profit in pips: b
    \n-----------------------------
    \n-- List of current open trades: com);




    THANK YOU!

  2. #2
    Furthermore, if you were able to code it accordingly if drawdown = X percent, the EA will attempt to shut for Xpercent of draw down rather (so I can set to a 1% or 3% reduction or whatever, sometimes recovery trades don't make it all the way back to break even or profit)

    Thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information