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
Wenn die Trendlinie durch die Trigger Pips verletzt wird, sollte ein Trade eingegeben werden ......
Please help it is driving me crazy!
#define EA_NAME Trader
#define MAGIC_NUMBER 456456
#define PARAM_ACTION ion
#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() {
//Raster für Bestellinformationen
Zeichenfolge 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
Zeichenfolge sEction = getParam (Name, 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 sLots = StrToDouble (get Param (Name, PARAM LOTS));
/determine trigger range
double dTriggerUpper = MathMax(dPrice,dPrice iTrigger*Point);
double dTriggerLower = MathMin(dPrice,dPrice iTrigger*Point);
/if within trigger range, submit an order
if (Bid lt;= dTriggerUpper Bid gt;= dTriggerLower) {
int iTicket = 0;
if (sAction == Buy) {
iTicket = OrderSend (Symbol (), OP_BUY, dLots, Ask, Slippage, Ask-iStopLoss * Punkt, Ask iTakeProfit * Punkt, Linie: 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_B REAKEVEN),iBreakEven);
GlobalVariableSet(getGlobalVarName(iTicket,PARAM_T RAILSTOP),iTrailStop);
/remove order info from the line
ObjectSetText(sName,);
}
else {
//Zum Ordnungsarray als ausstehende ion hinzufügen
ArrayResize(sGrid,ArrayRange(sGrid,0) 1);
int index = ArrayRange(sGrid,0)-1;
/Print(Name: ,sName, Action: , sAction, Index: , index);
sGrid [index] [GRID_ID] = sName;
sGrid[index][GRID_TYPE] = getParam(sName,PARAM_ACTION);
sGrid[index][GRID_TRIGGER] = getParam(sName,PARAM_TRIGGER);
sGrid[index][GRID_TP] = getParam(sName,PARAM_TAKEPROFIT);
sGrid[index][GRID_SL] = getParam(sName,PARAM_STOPLOSS);
sGrid [index] [GRID_TS] = getParam (sName, PARAM_TRAILSTOP);
sGrid [Index] [GRID BE] = get Param (Name, PARAM BREAKEVEN);
sGrid [index] [GRID_LOTS] = getParam (sName, PARAM_LOTS);
}
}
}
/Find open positions owned by this EA and manage them.
void doManagePositions(string sGrid[][]) {
/iterate all orders
for (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;
/see if there's a trailing stop or break even defined
/these would have been previously stored in global vars
int iTicket = OrderTicket();
int iBreakEven = GlobalVariableGet(getGlobalVarName(iTicket,PARAM_B REAKEVEN));
int iTrailStop = GlobalVariableGet(getGlobalVarName(iTicket,PARAM_T RAILSTOP));
Drucken (Trail:, iTrailStop);
//Stoploss-Wartung durchführen
double dNewStop = 0;
if (OrderType() == OP_BUY) {
//Breakeven prüfen
if (iBreakEven gt; 0 OrderOpenPrice() iBreakEven * Point lt;= Bid)
dNewStop = OrderOpenPrice();
/check trailstop
if (iTrailStop gt; 0)
dNewStop = MathMax(dNewStop,Bid-iTrailStop*Point);
//Stoploss bei Bedarf aktualisieren
if (dNewStop != 0 dNewStop gt; OrderStopLoss())
OrderModify(iTicket,OrderOpenPrice(),dNewStop,Orde rTakeProfit(),OrderExpiration());
}
if (OrderType() == OP_SELL) {
/check breakeven
if (iBreakEven gt; 0 OrderOpenPrice() - iBreakEven * Point gt;= Bid)
dNewStop = OrderOpenPrice ();
//Trailstop überprüfen
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, OrderTakeProfit (), OrderExpiration ());
}}
/add to orders array as an open position
ArrayResize(sGrid,ArrayRange(sGrid,0) 1);
int index = ArrayRange (sGrid, 0) -1;
sGrid[index][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[index][GRID_TP] = DoubleToStr(OrderTakeProfit(),Digits);
sGrid [index] [GRID_SL] = DoubleToStr (OrderStopLoss (), Digits);
sGrid[index][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;
Zeichenfolge Name;
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 = Grid (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 = Grid (i 1) _Type;
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 = Grid (i 1) _Trigger;
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 = Grid (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]);
}
}
Zeichenfolge getGlobalVarName (int iTicket, Zeichenfolge sParam) {
return(EA_NAME _ Symbol() _ iTicket _ sParam);
}
string getParam(string sLine, string sParam) {
/get description and drop an extra space at front and back
string desc = ObjectDescription(sLine) ;
/mod the param to match how it would be represented in the desc
sParam = sParam =;
//finde den Index des Parameters
int index = StringFind(desc,sParam);
/strip the description out from in front of the value
string value = StringSubstr(desc,index StringLen(sParam));
//entferne die Beschreibung hinter dem Wert
index = StringFind(value, );
if (index != -1) value = StringSubstr(value,0,index);
return(value);
}
double getLinePrice(string sObjName) {
int iObjType = ObjectType(sObjName);
//wenn es eine horizontale Linie ist ...
if (iObjType == OBJ_HLINE)
return(ObjectGet(sObjName,OBJPROP_PRICE1));
/if it's a trend line...
if (iObjType == OBJ_TREND)
return(ObjectGetValueByShift(sObjName,0));
//Andernfalls...
return(-1);
}
*
/Iterate over objects on this chart
für (int i = ObjectsTotal () - 1; igt; = 0; i--) {
string sObjName = ObjectName(i);
string sAction;
string sTrigger;
Zeichenfolge 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)
continue;
/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
sMessage = Alert triggered: Symbol() @ DoubleToStr(Bid,Digits) .
iProximity pips from sObjName .;
if (PopupAlert) Alert(sMessage);
if (E-Mail-Benachrichtigung) E-Mail senden (Benachrichtigung über Symbol (), Nachricht);
/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);
/if parn not found, no alert for this object
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 (Zeichenfolge 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,);
return;
}
/if found further on in desc, strip it from description
if (iSubStrOffset gt; 0) {
ObjectSetText (sObjName, StringSubstr (sObjDesc, 0, iSubStrOffset));
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.;
//Etikett erstellen und positionieren
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);
}}
*
Powered by vBulletin® Version 4.2.5 Copyright ©2026 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.