Why is this EA not working?
Results 1 to 3 of 3

Thread: Why is this EA not working?

  1. #1
    Hi,
    Can someone please help me understand why this EA is not working unless the ask manual confirmation button is ticked???

    A trendline drawn on the chart and the description field is populated with the trade parameters in a string such as Action=Buy Trigger=5 TP=60 SL=30 TS=45 BE=10 Lots=1.5

    Ketika garis tren dilanggar oleh pemicu pips, perdagangan harus dimasukkan ......

    Please help it is driving me crazy!


    #define EA_NAME Trader
    #define MAGIC_NUMBER 456456

    #define PARAM_ACTION Action
    #define PARAM_TRIGGER Trigger
    #define PARAM_TAKEPROFIT TP
    #define PARAM_STOPLOSS SL
    #define PARAM_TRAILSTOP TS
    #define PARAM_BREAKEVEN BE
    #define PARAM_LOTS Lots

    #define GRID_ID 0
    #define GRID_TYPE 1
    #define GRID_TRIGGER 2
    #define GRID_TP 3
    #define GRID_SL 4
    #define GRID_TS 5
    #define GRID_BE 6
    #define GRID_LOTS 7

    extern int Slippage = 30;
    extern bool EmailAlert = false;
    extern bool PopupAlert = false;



    int start () {

    //kisi untuk menyimpan info pesanan
    string sGrid [0] [8];
    ArrayResize(sGrid,0);

    /Inspect lines for pending orders
    doManageLineActions (sGrid);

    /Manage open positions
    /This is done after lines are checked so if an order is submid
    /it will show up in the grid as an open position.
    doManagePositions(sGrid);

    doDrawGrid(sGrid);

    return(0);
    }

    void doManageLineActions(string sGrid[][]) {

    /iterate all objects on chart
    for (int i=ObjectsTotal()-1;igt;=0;i--){

    /get object name and price at current bar
    /if no price then simply move on
    string sName = ObjectName(i);
    double dPrice = getLinePrice(sName);

    if (dPrice lt; 0) continue;

    /get the par for the object starting with Action.
    /if action isn't defined then simply move on
    string sAction = getParam(sName,PARAM_ACTION);
    if (sAction != Buy sAction != Sell) continue;

    int iTrigger = StrToInteger(getParam(sName,PARAM_TRIGGER));
    int iTakeProfit = StrToInteger(getParam(sName,PARAM_TAKEPROFIT));
    int iStopLoss = StrToInteger(getParam(sName,PARAM_STOPLOSS));
    int iTrailStop = StrToInteger (getParam (sName, PARAM_TRAILSTOP));
    int iBreakEven = StrToInteger (getParam (sName, PARAM_BREAKEVEN));
    double dLots = StrToDouble(getParam(sName,PARAM_LOTS));

    /determine trigger range
    double dTriggerUpper = MathMax(dPrice,dPrice iTrigger*Point);
    double d'TriggerLower = MathMin (d'Harga, Harga Trigger * Point);

    //jika dalam rentang pemicu, kirim pesanan
    if (Bid lt;= dTriggerUpper Bid gt;= dTriggerLower) {
    int iTicket = 0;
    if (sAction == Buy) {
    iTicket = OrderSend (Simbol (), OP_BUY, dLots, Ask, Slippage, Ask-iStopLoss * Point, Ask iTakeProfit * Point, Baris: sName, MAGIC_NUMBER);
    }
    else if (sAction == Sell) {
    iTicket = OrderSend(Symbol(),OP_SELL,dLots,Bid,Slippage,Bid iStopLoss*Point,Bid-iTakeProfit*Point,Line: sName,MAGIC_NUMBER);
    }

    /add trailstop and breakeven to globalvars to allow tracking through EA restart
    GlobalVariableSet (getGlobalVarName (iTicket, PARAM_BREAKEVEN), iBreakEven);
    GlobalVariableSet(getGlobalVarName(iTicket,PARAM_T RAILSTOP),iTrailStop);
    //hapus info pesanan dari baris
    ObjectSetText(sName,);
    }
    lain {
    /add to orders array as a pending action
    ArrayResize(sGrid,ArrayRange(sGrid,0) 1);
    int index = ArrayRange(sGrid,0)-1;

    /Print(Name: ,sName, Action: , sAction, Index: , index);
    sGrid [indeks] [GRID_ID] = sName;
    sGrid[index][GRID_TYPE] = getParam(sName,PARAM_ACTION);
    sGrid[index][GRID_TRIGGER] = getParam(sName,PARAM_TRIGGER);
    sGrid [indeks] [GRID_TP] = dapatkan Param (Nama, PARAM TAKEPROFIT);
    sGrid[index][GRID_SL] = getParam(sName,PARAM_STOPLOSS);
    sGrid [indeks] [GRID_TS] = getParam (sName, PARAM_TRAILSTOP);
    sGrid[index][GRID_BE] = getParam(sName,PARAM_BREAKEVEN);
    sGrid [indeks] [GRID_LOTS] = getParam (sName, PARAM_LOTS);
    }
    }
    }

    /Find open positions owned by this EA and manage them.
    batal doManagePositions (string sGrid [] []) {

    /iterate all orders
    untuk (int i = OrdersTotal () - 1; igt; = 0; i--) {

    /select the order
    OrderSelect(i,SELECT_BY_POS);

    /if not for this symbol or EA, move on
    if (OrderSymbol()!=Symbol()) continue;
    if (OrderMagicNumber() != MAGIC_NUMBER) continue;

    //lihat apakah ada trailing stop atau break even yang ditentukan
    /these would have been previously stored in global vars
    int iTicket = OrderTicket();
    int iBreakEven = GlobalVariableGet (getGlobalVarName (iTicket, PARAM_BREAKEVEN));
    int iTrailStop = GlobalVariableGet(getGlobalVarName(iTicket,PARAM_T RAILSTOP));
    Print(Trail:, iTrailStop);

    /perform stoploss maintenance
    double dNewStop = 0;
    if (OrderType() == OP_BUY) {
    /check breakeven
    if (iBreakEven gt; 0 OrderOpenPrice() iBreakEven * Point lt;= Bid)
    dNewStop = OrderOpenPrice();
    /check trailstop
    if (iTrailStop gt; 0)
    dNewStop = MathMax(dNewStop,Bid-iTrailStop*Point);
    /update stoploss if required
    if (dNewStop != 0 dNewStop gt; OrderStopLoss())
    OrderModify(iTicket,OrderOpenPrice(),dNewStop,Orde rTakeProfit(),OrderExpiration());
    }
    if (OrderType () == OP_SELL) {
    //periksa titik impas
    if (iBreakEven gt; 0 OrderOpenPrice() - iBreakEven * Point gt;= Bid)
    dNewStop = OrderOpenPrice();
    /check trailstop
    if (iTrailStop gt; 0)
    if (dNewStop == 0) dNewStop = Bid-iTrailStop*Point;
    else dNewStop = MathMax(dNewStop,Bid-iTrailStop*Point);
    /update stoploss if required
    if (dNewStop != 0 dNewStop lt; OrderStopLoss())
    OrderModify(iTicket,OrderOpenPrice(),dNewStop,Orde rTakeProfit(),OrderExpiration());
    }

    /add to orders array as an open position
    ArrayResize (sGrid, ArrayRange (sGrid, 0) 1);
    int index = ArrayRange(sGrid,0)-1;
    sGrid [indeks] [GRID_ID] = iTicket;
    if (OrderType() == OP_BUY) sGrid[index][GRID_TYPE] = Buy;
    if (OrderType() == OP_SELL) sGrid[index][GRID_TYPE] = Sell;
    sGrid[index][GRID_TRIGGER] = ;
    sGrid [indeks] [GRID_TP] = DoubleToStr (OrderTakeProfit (), Digit);
    sGrid[index][GRID_SL] = DoubleToStr(OrderStopLoss(),Digits);
    sGrid [indeks] [GRID_TS] = iTrailStop;
    sGrid[index][GRID_BE] = iBreakEven;
    sGrid[index][GRID_LOTS] = OrderLots();
    }
    }


    void doDrawGrid(string sGrid[][]) {

    int col1 = 5;
    int col2 = col1 200;
    int col3 = col2 80;
    int col4 = col3 80;
    int col5 = col4 80;
    int col6 = col5 80;
    int col7 = col6 80;
    int col8 = col7 80;
    string sName;

    for (int i=ObjectsTotal()-1;igt;=0;i--) {
    sName = ObjectName(i);
    if (StringFind(sName,Grid) ==0) ObjectDelete(sName);
    }

    /create column labels
    sName = Grid0_ID;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col1);
    ObjectSet (sName, OBJPROP_YDISTANCE, 15);
    ObjectSetText (sName, ID);
    }
    sName = Grid0_Type;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet (sName, OBJPROP_XDISTANCE, col2);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText (sName, Type);
    }
    sName = Grid0_Trigger;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col3);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText(sName,Trigger);
    }
    sName = Grid0_TakeProfit;
    if (ObjectFind(sName) == -1) {
    ObjectCreate (sName, OBJ_LABEL, 0,0,0);
    ObjectSet (sName, OBJPROP_XDISTANCE, col4);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText(sName,TakeProfit);
    }
    sName = Grid0_StopLoss;
    if (ObjectFind(sName) == -1) {
    ObjectCreate (sName, OBJ_LABEL, 0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col5);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText(sName,StopLoss);
    }
    sName = Grid0_TrailStop;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col6);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText(sName,TrailStop);
    }
    sName = Grid0_BreakEven;
    if (ObjectFind (sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet (sName, OBJPROP_XDISTANCE, col7);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText (sName, BreakEven);
    }
    sName = Grid0_Lots;
    if (ObjectFind(sName) == -1) {
    ObjectCreate (sName, OBJ_LABEL, 0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col8);
    ObjectSet(sName,OBJPROP_YDISTANCE,15);
    ObjectSetText(sName,Lots);
    }

    /iterate objects in grid array and draw them
    for (i=0;ilt;ArrayRange(sGrid,0);i ) {

    int yOffset = 15 (i 1)*15;

    sName = Kotak (i 1) _ ID;
    if (ObjectFind(sName) == -1) {
    ObjectCreate (sName, OBJ_LABEL, 0,0,0);
    ObjectSet (sName, OBJPROP_XDISTANCE, col1);
    ObjectSet (sName, OBJPROP_YDISTANCE, yOffset);
    }
    ObjectSetText(sName,sGrid[i][GRID_ID]);
    sName = Kotak (i 1) _ Ketik;
    if (ObjectFind (sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col2);
    ObjectSet (sName, OBJPROP_YDISTANCE, yOffset);
    }
    ObjectSetText(sName,sGrid[i][GRID_TYPE]);
    sName = Kotak (i 1) _ Pemicu;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col3);
    ObjectSet(sName,OBJPROP_YDISTANCE,yOffset);
    }
    ObjectSetText(sName,sGrid[i][GRID_TRIGGER]);
    sName = Grid (i 1) _TakeProfit;
    if (ObjectFind(sName) == -1) {
    ObjectCreate (sName, OBJ_LABEL, 0,0,0);
    ObjectSet (sName, OBJPROP_XDISTANCE, col4);
    ObjectSet(sName,OBJPROP_YDISTANCE,yOffset);
    }
    ObjectSetText(sName,sGrid[i][GRID_TP]);
    sName = Grid (i 1) _StopLoss;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col5);
    ObjectSet (sName, OBJPROP_YDISTANCE, yOffset);
    }
    ObjectSetText (sName, sGrid [i] [GRID_SL]);
    sName = Kotak (i 1) _ TrailStop;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col6);
    ObjectSet(sName,OBJPROP_YDISTANCE,yOffset);
    }
    ObjectSetText(sName,sGrid[i][GRID_TS]);
    sName = Grid (i 1) _BreakEven;
    if (ObjectFind(sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col7);
    ObjectSet(sName,OBJPROP_YDISTANCE,yOffset);
    }
    ObjectSetText (sName, sGrid [i] [GRID_BE]);
    sName = Grid (i 1) _Lots;
    if (ObjectFind (sName) == -1) {
    ObjectCreate(sName,OBJ_LABEL,0,0,0);
    ObjectSet(sName,OBJPROP_XDISTANCE,col8);
    ObjectSet(sName,OBJPROP_YDISTANCE,yOffset);
    }
    ObjectSetText (sName, sGrid [i] [GRID_LOTS]);
    }


    }


    string getGlobalVarName(int iTicket, string sParam) {

    return(EA_NAME _ Symbol() _ iTicket _ sParam);
    }

    string getParam (string sLine, string sParam) {

    //dapatkan deskripsi dan berikan ruang ekstra di depan dan belakang
    string desc = Deskripsi Objek (sLime) ;

    /mod the param to match how it would be represented in the desc
    sParam = sParam =;

    /find the index of the param
    int index = StringFind(desc,sParam);

    /strip the description out from in front of the value
    nilai string = StringSubstr (desc, index StringLen (sParam));

    /strip the description out from behind the value
    index = StringFind (value,);
    if (index != -1) value = StringSubstr(value,0,index);

    return(value);
    }

    gandakan getLinePrice (string sObjName) {

    int iObjType = ObjectType(sObjName);

    /if it's a horizontal line...
    if (iObjType == OBJ_HLINE)
    return(ObjectGet(sObjName,OBJPROP_PRICE1));

    /if it's a trend line...
    if (iObjType == OBJ_TREND)
    return(ObjectGetValueByShift(sObjName,0));

    /otherwise...
    return (-1);
    }



    /*

    /Iterate over objects on this chart
    for (int i=ObjectsTotal()-1;igt;=0;i--) {
    string sObjName = ObjectName(i);
    string sAction;
    string sTrigger;
    string sTakeProfit;
    string sStopLoss;
    string sTrailStop;
    string sBreakEven;
    string sLots;

    /if it's not a horizontal line or trend line, continue
    if (ObjectType (sObjName)! = OBJ_HLINE ObjectType (sObjName)! = OBJ_TREND)
    continue;

    /Is no action on this object, continue
    sAction = getParam(sObjName,Action);
    if (sAction != Buy sAction != Sell)
    terus;

    /Is the line within alert proximity? If not, continue iteration
    iProximity = MathAbs(Bid - dObjPrice)Point;
    if (iProximity gt; iObjAlert) continue;

    /Fire the alert and clear alert from description
    Pesan = Peringatan dipicu: Simbol () @ DoubleToStr (Tawaran, Digit) .
    iProximity pips from sObjName .;
    if (PopupAlert) Alert(sMessage);
    if (EmailAlert) SendMail(Alert on Symbol(), sMessage);

    /Clear the alert from the object description
    clearObjectAlert(sObjName);
    }










    int getObjectAlert(string sObjName) {

    /looking for parn alert_## at end of obj description
    string sObjectDesc = ObjectDescription(sObjName);
    int iParnOffset = StringFind(sObjectDesc,OBJDESC_PATTERN);
    int iParnLength = StringLen(OBJDESC_PATTERN);

    //jika parn tidak ditemukan, tidak ada peringatan untuk objek ini
    if (iParnOffset == -1)
    return(-1);

    /return value after the parn as number
    /Print(Alert: , StringSubstr(sObjectDesc,iParnOffset iParnLength));
    return(StrToInteger(StringSubstr(sObjectDesc,iParn Offset iParnLength)));
    }

    void clearObjectAlert(string sObjName) {

    /strip alert_* from end of obj description
    string sObjDesc = ObjectDescription(sObjName);
    int iSubStrOffset = StringFind(sObjDesc,Alert_);

    /if found at start of description, clear description
    if (iSubStrOffset == 0) {
    ObjectSetText(sObjName,);
    kembali;
    }

    /if found further on in desc, strip it from description
    if (iSubStrOffset gt; 0) {
    ObjectSetText(sObjName,StringSubstr(sObjDesc,0,iSu bStrOffset));
    return;
    }
    }

    void createAlertLabel(string sObjName) {

    /Set the text
    string sObjText = Alerter:;
    if (EmailAlert) sObjText = sObjText Emails Alerts ON.;
    else sObjText = sObjText Emails Alerts OFF.;
    if (PopupAlert) sObjText = sObjText Popup Alerts ON .;
    else sObjText = sObjText Popup Alerts OFF.;

    /Create and position the label
    ObjectCreate(sObjName,OBJ_LABEL,0,0,0);
    ObjectSetText (sObjName, sObjText, 8, Arial, Yellow);
    ObjectSet (sObjName, OBJPROP_XDISTANCE, 5);
    ObjectSet (sObjName, OBJPROP_YDISTANCE, 5);
    ObjectSet(sObjName,OBJPROP_CORNER,1);

    }

    */

  2. #2
    Hi tte Just had à quick look at your EA....it has no init and deinit function...and you need it....

  3. #3
    init and deinit are not needed, even this code will work as is: Inserted Code int cnt=0; void start(){cnt ;Comment(Ticks from start ,cnt);} but I get many errors on this ea - there are so many undefined parameters

Similar Threads

  1. Encog Neural Network Integration dengan Metatrader 5 EA Working Example
    By kemges37 in forum Pembicaran Bitcoin dan Mata Uang Kripto
    Balasan: 2
    Postingan Terakhir: 08-02-2021 22:35, 10:35 PM

Izin Posting

  • Anda tidak boleh memposting thread baru
  • Anda tidak boleh memposting balasan
  • Anda tidak boleh memposting lampiran
  • Anda tidak boleh menyunting postingan Anda
  •  
  • Kode BB Aktif
  • Smilies Aktif
  • Kode [IMG] Aktif
  • Kode [VIDEO] Aktif
  • Kode HTML tidak aktif
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.