How to code? - page 58

 

I thought I had fixed it but no.

What I am trying to do is have a comment on the chart and in the journal stating which entry condition was used to open the current position.

Has this been done before and how do you do it because I have been trying for a while now but no luck and it's not as easy as I thought.

Below is my latest attempt.

any help would be great

buysig = Long || Long2 || Long3 || Long4;

sellsig = Short || Short2 || Short3 || Short4;

closebuy=sellsig;

closesell=buysig;

if (curprof>=AccountEquity()*ProfitExit/100.0) {

exit=true;

}

if (last>0 && (Time[0]-last)/(Period()*60)>=CancelOrderBars) {

remorder=true;

}

}

void CheckForOpen() {

int res,tr;

//---- sell conditions

co=CalculateCurrentOrders(Symbol());

if(sellsig && lastsig!=-1) {

if ( Short == true)Print(" Short signal taken ");

if ( Short2 == true)Print(" Short2 signal taken ");

if ( Short3 == true)Print(" Short3 signal taken ");

if ( Short4 == true)Print(" Short4 signal taken ");

co=CalculateCurrentOrders(Symbol());

if (co==0) {

res = OpenStop(OP_SELLSTOP,LotsRisk(StopLoss), Low[shift]-OrderPipsDiff*Point, StopLoss, TakeProfit1);

}

lastsig=-1;

last=Time[0];

return;

}

//---- buy conditions

co=CalculateCurrentOrders(Symbol());

if(buysig && lastsig!=1) {

if ( Long == true) Print(" Long signal taken ");

if ( Long2 == true)Print(" Long2 signal taken ");

if ( Long3 == true) Print(" Long3 signal taken ");

if ( Long4 == true)Print(" Long4 signal taken ");

co=CalculateCurrentOrders(Symbol());

if (co==0) {

res = OpenStop(OP_BUYSTOP,LotsRisk(StopLoss), High[shift]+OrderPipsDiff*Point, StopLoss, TakeProfit1);

}

last=Time[0];

lastsig=1;

return;

}

}

bool CloseAtMarket(int ticket,double lot) {

//fault tolerant market order closing

bool bres=false; int tr;

tries=0;

while (!bres && tries<OrderTriesNumber) {

RefreshRates();

bres=OrderClose(ticket,lot,OrderClosePrice(),slippage,White);

tries++;

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

}

if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError()));

}

int OpenStop(int mode,double lot, double prc, int SL, int TP) {

int res,tr,col;

string mail;

double openprice,sl,tp,stlev;

tries=0;

stlev=(1+MarketInfo(Symbol(),MODE_STOPLEVEL))*Point;

while (res<=0 && tries<OrderTriesNumber) {

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

RefreshRates();

if (mode==OP_SELLSTOP) {

if (prc<=Bid-stlev) openprice=prc;

else openprice=Bid-stlev;

if (SL>0) sl=openprice+SL*Point;

if (TP>0) tp=openprice-TP*Point;

col=Red;

} else

if (mode==OP_BUYSTOP) {

if (prc>=Ask+stlev) openprice=prc;

else openprice=Ask+stlev;

if (SL>0) sl=openprice-SL*Point;

if (TP>0) tp=openprice+TP*Point;

col=Blue;

} else return;

Print(Ask," ",Bid," ",Symbol()," ",mode," ",lot," ",openprice," ",sl," ",tp," ");

res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+"_"+ MagicNumber, MagicNumber,0,col);

tries++;

}

if (res<=0) Print("Error opening pending order : ",ErrorDescription(GetLastError()));

return(res);

 

This EA wont even compile, stoploss should be the lest of your concerns. There are 5 Variables that have random spaces in them or the first letter isn't capitalized!

 
jturns23:
This EA wont even compile, stoploss should be the lest of your concerns. There are 5 Variables that have random spaces in them or the first letter isn't capitalized!

Here the fix version.

But this still can't open any position because there is no logic in the code for decide how to open long / short positions.

 
 

Help with this EA

Michel:
Who is this CHinGsMAroonCLK ?

As I remember, this EA is nothing else than 10p3 from elCactus, but maybe I am wrong...

Check it's thread, you will probably find what you are looking for: https://www.mql5.com/en/forum/174975

Ok.. so now the thing is i can'y put a stoploss for this EA.. whats the code? can help me? thanx

 

none trading zone - code help

Hello everyone,

I trying to tweak a code but after much effort I still couldn't get it right.. if any of you guys dont mind can you have a look at this.. appreciate..

The idea is to stop the next trade if the price range is in the same zone as the previous trade. Long trade will check zone for last OPEN POSITION long trade, and short trade will check zone for last OPEN POSITION short trade.

ie. if the first LONG at 1.4000, then the second LONG will only trigger if the price move out of the zone (20 pips zone) less than 1.3990 && more than 1.4010

Thanks everyone..

//+------------------------------------------------------------------------------------------------------------------------+

//| Filter for sideways market - preventing multiple trade in similar price range and create no-trade zone |

//+------------------------------------------------------------------------------------------------------------------------+

extern int Zone1 = -10; // (lower zone)

extern int Zone2 = 10; // (upper zone)

// no trade zone between -10 and +10 from the previous trade

bool CheckZone(int type)

{

int cnt = OrdersTotal();

for (int i=0; i < cnt; i++)

{

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderMagicNumber() != Magic) continue;

if (OrderType() != type) continue;

if (type == OP_BUY)

{

if( (Bid - OrderOpenPrice()) > Zone1*Point && (Bid - OrderOpenPrice()) < Zone2*Point ) return(false);

}

if (type == OP_SELL)

{

if( (OrderOpenPrice()-Ask) > Zone1*Point && (OrderOpenPrice()-Ask) < Zone2*Point ) return(false);

}

}

return (true);

}

 

Resolve The EA Problem

Hello there all MQL Programmers,

Please check the following code and tell me why this is not placing the trades at my demo account. Its good EA on GJ 1m but unfortunately its not working. Can anyone fix it please and make it usable as a bug free EA.

I am thankfully in advance!

Best Regards.

//+------------------------------------------------------------------+

extern int Length1 = 3;

extern int Length2 = 10;

extern int Length3 = 16;

double Histo[];

double MaHisto[];

double up[];

double dn[];

double upMode[];

double dnMode[];

int alertBar;

int init()

{

return(0);

}

int deinit()

{

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars<0) counted_bars=0;

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i = 0 ;i <= limit ;i++)Histo = iMA(Symbol(),0,Length1,0,MODE_EMA,PRICE_CLOSE,i) - iMA(Symbol(),0,Length2,0,MODE_EMA,PRICE_CLOSE,i);

for(int j = 0 ;j <= limit ;j++)MaHisto[j] = iMAOnArray(Histo,0,Length3,0,MODE_EMA,j);

for(int m = 0 ;m <= limit ;m++)

{

if(MaHisto[m+1] 0)

{

up[m] = Open[m]-(5*Point);

if(Bars > alertBar && m == 0)

{

//Alert(Symbol()+" "+Period()+" KI LONG ",Ask);

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,25,15,0,0,0,Red);

alertBar = Bars;

}

}

else if(MaHisto[m+1] >= 0 && MaHisto[m]< 0)

{

dn[m] = Open[m]+(5*Point);

if(Bars > alertBar && m == 0)

{

OrderSend(Symbol(),OP_SELL,0.1,Ask,3,25,15,0,0,0,Red);

alertBar = Bars;

}

}

else

{

up[m] = EMPTY_VALUE;

dn[m] = EMPTY_VALUE;

}

if( MaHisto[m] > 0 )

{

upMode[m] = High[m];

dnMode[m] = Low[m];

}

else if( MaHisto[m] < 0 )

{

dnMode[m] = High[m];

upMode[m] = Low[m];

}

}

return(0);

}

//+------------------------------------------------------------------+

 
arsenic786:
Hello there all MQL Programmers,

Please check the following code and tell me why this is not placing the trades at my demo account. Its good EA on GJ 1m but unfortunately its not working. Can anyone fix it please and make it usable as a bug free EA.

I am thankfully in advance!

Best Regards.

//+------------------------------------------------------------------+

extern int Length1 = 3;

extern int Length2 = 10;

extern int Length3 = 16;

double Histo[];

double MaHisto[];

double up[];

double dn[];

double upMode[];

double dnMode[];

int alertBar;

int init()

{

return(0);

}

int deinit()

{

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars<0) counted_bars=0;

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i = 0 ;i <= limit ;i++)Histo = iMA(Symbol(),0,Length1,0,MODE_EMA,PRICE_CLOSE,i) - iMA(Symbol(),0,Length2,0,MODE_EMA,PRICE_CLOSE,i);

for(int j = 0 ;j <= limit ;j++)MaHisto[j] = iMAOnArray(Histo,0,Length3,0,MODE_EMA,j);

for(int m = 0 ;m <= limit ;m++)

{

if(MaHisto[m+1] 0)

{

up[m] = Open[m]-(5*Point);

if(Bars > alertBar && m == 0)

{

//Alert(Symbol()+" "+Period()+" KI LONG ",Ask);

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,25,15,0,0,0,Red);

alertBar = Bars;

}

}

else if(MaHisto[m+1] >= 0 && MaHisto[m]< 0)

{

dn[m] = Open[m]+(5*Point);

if(Bars > alertBar && m == 0)

{

OrderSend(Symbol(),OP_SELL,0.1,Ask,3,25,15,0,0,0,Red);

alertBar = Bars;

}

}

else

{

up[m] = EMPTY_VALUE;

dn[m] = EMPTY_VALUE;

}

if( MaHisto[m] > 0 )

{

upMode[m] = High[m];

dnMode[m] = Low[m];

}

else if( MaHisto[m] < 0 )

{

dnMode[m] = High[m];

upMode[m] = Low[m];

}

}

return(0);

}

//+------------------------------------------------------------------+

"OrderSend(Symbol(),OP_SELL,0.1,Ask,3,25,15,0,0,0,R ed); "

You are selling at the Ask price, should be Bid.

The Comment field should be "", not 0.

25 as SL should be Bid+25*Point.

15 as TP should be Bid-15*Point.

"R ed" is not a color.

 
Michel:
"OrderSend(Symbol(),OP_SELL,0.1,Ask,3,25,15,0,0,0,R ed); "

You are selling at the Ask price, should be Bid.

The Comment field should be "", not 0.

25 as SL should be Bid+25*Point.

15 as TP should be Bid-15*Point.

"R ed" is not a color.

Thank you very much for your support!

But, I am still facing problems zero knowledge of MQL. Can you please copy paste the code in mq4 file and test it on demo and then tell me if it works fine. Your support will be counted as Kindest Help Michel.

Best Regards,

Kashif.

 

No, sorry, I do not have enough time for now.

In few hours I take a boat to go back to my family for Xmas ... and no more pc...