How to code? - page 176

 

Atr decresing code ???

Atr decresing - what is the code mql4 ?

--------------------------------------------------------------------------------

Atr decresing

what is the code mql4 ?

I would like that the my ea not open positions if

the ATR d1 is > ATR d1 (-1)

 

How to code 3 levels of Trailing Stops

TrailingStop = 50;

TrailingStop_Over100 =30;

TrailingStop_Over150 = 20;

Level 1: 0-100 pip profit - TS is 50 pips

Level 2: 101-150 pip profit - TS changes to 30 pips

Level 3: 151+ pip profit - TS changes to 20 pips

How do I code this (Positive direction move) so the TS will change once pip profit increases??

Dave

<<<

Really would appreciate the expertise of a coder.

 

after first cross set several bars distance

Hi to all programmer guru's here i am a newbie in mql4 programming and i stuck on a problem,

so it is the following :

i have 2 EMA 5 and 20 PERIOD_15 and respectivly 5 and 20 EMA on PERIOD_H1.

So when i am entering a posision with the first cross PERIOD_M15, the advisor close the position immediatly in the same bar if the prise move the other way and made a reverse cross. This is programmatically correct, but my acctual problem is to wait for the next 1-2 or more bars and then close the position if cross found.

So can you help me to do that ? if some related topic with the same problem is here, can you send me a link

and the Moderators can remove the post .

thx in advance!!

--if you allready have an open position

-- if too much crosses occurs

-- wait a little bit before exit of this position

--this should solve the repeated crosses in one bar

if(firstCross == 1)

{

---------------------------//Close, check if next several bar's printed after OpenOrderPrise()-----------------------------------

if(openbar <= closebar)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Red); // close position

return(0); // exit

}else

return(0);

}

well i found some creepy solution i've allready attached

If you have some optimizing ideas for time shifting or optimizing ideas in the code at all, i will appreciate any suggestions thx in advance

Files:
 

Need your help

Hi traders,

I will really appreciate it if someone can help me to develop alert to this indicator ( MT4-LevelStop-Reverse-vB0-3).

I wants the alert to ring immediately the arrow show up.

Thanks in advance.

 
chiwing:
hi,

i use your lucky v2, and want to know the code of adding text on the chart which is not using the object--label-->see the pic ~~

and user cannot del the text~ ~

the text is being like that-- "Your lucky is free and still on developing..."

how to code it?

thanks

Use command Comment()

Comment - MQL4 Documentation

 

how to code some uneliminateAble text on chart

hi,

i use your lucky v2, and want to know the code of adding text on the chart which is not using the object--label-->see the pic ~~

and user cannot del the text~ ~

the text is being like that-- "Your lucky v2 EA is free and still on developing..."

how to code it?

thanks

Files:
how_to_code.jpg  134 kb
 

Multiple order and multiple trailing

In my Ea i use multiple order, one at market and other with buy/sell limit

Whne i get the 3 entry like in example i want that trailing start togheter and work togheter

An example

1 entry at 1.50

2entry at 1.4950

3 entry at 1.4930

the trailing is 50 point, but i want that start when reach 1.5050 not before, if i use normal trailing when the price reach 1.5001 the second entry (if it is filled) start to trail but i don't want it... i want that the trailing start with 50 pip and all at the same price so at 1.5050

so is better to save the ticket to undertand wich order i use?

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Point*StopLoss,Ask+TakeProfit*Point,0,0,Green);

LastClosedBar = Time[0];

RefreshRates();

OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);

entratalong= OrderOpenPrice( );

ticket2=OrderSend(Symbol(),OP_BUYLIMIT,Lots_2ingresso,entratalong-Point*Secentrata-2*Point,3,entratalong-Point*StopLoss-2*Point,entratalong+TakeProfit*Point,NULL,1,0,Magenta); // NULL, c'e il null in + //

ticket3=OrderSend(Symbol(),OP_BUYLIMIT,Lots_3ingresso,entratalong-Point*Terzentrata-2*Point,3,entratalong-Point*StopLoss-2*Point,entratalong+TakeProfit*Point,NULL,2,0,Magenta); // buono dei test //

[/CODE]

Here the trailign stop, it don't work the trail 1 e trail 2 with at the same time i control the ticket!!!

[CODE]

int TrailStop ()

{

int cnt,result,total=OrdersTotal();

double gain2=Lots_2ingresso;

double gain3=Lots_2ingresso;

int ticket,ticket2,ticket3;

for(cnt = total-1; cnt >= 0; cnt--)

{

RefreshRates();

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if ((OrderSymbol() == Symbol()) && (OrderProfit() > 0.00))

{

if (OrderType()==OP_BUY && OrderTicket()==ticket )

{

if(Bid - OrderOpenPrice() > Point * TrailingStop )

{

if(OrderStopLoss() < Bid - Point * TrailingStop)

{

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

for(cnt = total-1; cnt >= 0; cnt--)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if( OrderType()!=OP_SELL && OrderType()!=OP_BUY) //&& trail==1 && OrdersTotal() > 1 )

result =OrderDelete(OrderTicket());

}

Alert("sta facendo trail");

}

}

}

// trailing 2 parte X pip dopo

if (OrderType()==OP_BUY && OrderTicket()==ticket2)

{

if(Bid - OrderOpenPrice() > Point * Trailing2)

{

if(OrderStopLoss() < Bid - Point * TrailingStop)

{

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

}

}

}

// trailing 3 parte X pip dopo

if (OrderType()==OP_BUY )

{

if(Bid - OrderOpenPrice() > Point * Trailing3)

{

if(OrderStopLoss() < Bid - Point * TrailingStop)

{

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

}

}

}// fine trailing

 

Please change this code EMA

This is an excellent code by: Coders Guru. Can someone please change it for me. I need it to only CLOSE the open trades. I have created a system that tells me when to open trades and do not want to sit at the computer all day

in order to close trades. Thanks Team.

 

Change the code please

Calvon:
This is an excellent code by: Coders Guru. Can someone please change it for me. I need it to only CLOSE the open trades. I have created a system that tells me when to open trades and do not want to sit at the computer all day in order to close trades. Thanks Team.

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

//| EMA_6_12.mq4 |

//| Coders Guru |

//| Forex TSD| Metatrader Indicators and Experts Advisors |

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

#property copyright "Coders Guru"

#property link "https://www.forex-tsd.com"

//---- Includes

#include

//---- Trades limits

extern double TrailingStop = 40;

extern double TakeProfit = 1000; //any big number

extern double Lots = 1;

extern int Slippage = 5;

//--- External options

extern int CurrentBar = 1;

extern bool UseClose = true;

//--- Indicators settings

extern int MaMode = 1; /* MODE_SMA 0 MODE_EMA 1 MODE_SMMA 2 MODE_LWMA 3 */

extern int ShortEma = 4;

extern int LongEma = 8;

//--- Global variables

int MagicNumber = 123430;

string ExpertComment = "EMA_4_8";

bool LimitPairs = false;

bool LimitFrame = false;

int TimeFrame = 60;

string LP[] = {"EURUSD","USDJPY","AUDUSD","GBPUSD","EURGBP","USDCHF"}; // add/remove the paris you want to limit.

bool Optimize = false;

int NumberOfTries = 5;

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

int init()

{

return(0);

}

int deinit()

{

return(0);

}

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

bool isNewSymbol(string current_symbol)

{

//loop through all the opened order and compare the symbols

int total = OrdersTotal();

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

string selected_symbol = OrderSymbol();

if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)

return (False);

}

return (True);

}

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

int Crossed()

{

double EmaLongPrevious = iMA(NULL,0,LongEma,0,MaMode, PRICE_CLOSE, CurrentBar+1);

double EmaLongCurrent = iMA(NULL,0,LongEma,0,MaMode, PRICE_CLOSE, CurrentBar);

double EmaShortPrevious = iMA(NULL,0,ShortEma,0,MaMode, PRICE_CLOSE, CurrentBar+1);

double EmaShortCurrent = iMA(NULL,0,ShortEma,0,MaMode, PRICE_CLOSE, CurrentBar);

if (EmaShortPreviousEmaLongCurrent ) return (1); //up trend

if (EmaShortPrevious>EmaLongPrevious && EmaShortCurrent<EmaLongCurrent ) return (2); //down trend

return (0); //elsewhere

}

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

int start()

{

int cnt, ticket, total,n;

double trend ;

if(Bars<100) {Print("bars less than 100"); return(0);}

if(LimitFrame)

{

if(Period()!=TimeFrame) {Print("This EA is not working with this TimeFrame!"); return(0);}

}

if(LimitPairs)

{

if(AllowedPair(Symbol()) == false) {Print("This EA is not working with this Currency!"); return(0);}

}

//--- Trading conditions

bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;

if (Crossed() == 1 )

BuyCondition = false;

if (Crossed ()== 2 )

SellCondition = false;

if (Crossed ()== 1)

CloseBuyCondition = true;

if (Crossed ()== 1)

CloseSellCondition = true;

total = OrdersTotal();

if(total < 1 || isNewSymbol(Symbol()))

{

if(BuyCondition) //<-- BUY condition

{

ticket = OpenOrder(OP_BUY); //<-- Open BUY order

CheckError(ticket,"BUY");

return(0);

}

if(SellCondition) //<-- SELL condition

{

ticket = OpenOrder(OP_SELL); //<-- Open SELL order

CheckError(ticket,"SELL");

return(0);

}

return(0);

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) //<-- Long position is opened

{

if(UseClose)

{

if(CloseBuyCondition) //<-- Close the order and exit!

{

CloseOrder(OrderType()); return(0);

}

}

TrailOrder(OrderType()); return(0); //<-- Trailling the order

}

if(OrderType()==OP_SELL) //<-- Go to short position

{

if(UseClose)

{

if(CloseSellCondition) //<-- Close the order and exit!

{

CloseOrder(OP_SELL); return(0);

}

}

TrailOrder(OrderType()); return(0); //<-- Trailling the order

}

}

}

return(0);

}

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

int OpenOrder(int type)

{

int ticket=0;

int err=0;

int c = 0;

if(type==OP_BUY)

{

for(c = 0 ; c < NumberOfTries ; c++)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,Ask+TakeProfit*Point,ExpertComment,MagicNumber,0,Green);

err=GetLastError();

if(err==0)

{

break;

}

else

{

if(err==4 || err==137 ||err==146 || err==136) //Busy errors

{

Sleep(5000);

continue;

}

else //normal error

{

break;

}

}

}

}

if(type==OP_SELL)

{

for(c = 0 ; c < NumberOfTries ; c++)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,Bid-TakeProfit*Point,ExpertComment,MagicNumber,0,Red);

err=GetLastError();

if(err==0)

{

break;

}

else

{

if(err==4 || err==137 ||err==146 || err==136) //Busy errors

{

Sleep(5000);

continue;

}

else //normal error

{

break;

}

}

}

}

return(ticket);

}

bool CloseOrder(int type)

{

if(OrderMagicNumber() == MagicNumber)

{

if(type==OP_BUY)

return (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet));

if(type==OP_SELL)

return (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet));

}

}

void TrailOrder(int type)

{

if(TrailingStop>0)

{

if(OrderMagicNumber() == MagicNumber)

{

if(type==OP_BUY)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

}

}

}

if(type==OP_SELL)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

}

}

}

}

}

}

void CheckError(int ticket, string Type)

{

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print(Type + " order opened : ",OrderOpenPrice());

}

else Print("Error opening " + Type + " order : ", ErrorDescription(GetLastError()));

}

bool AllowedPair(string pair)

{

bool result=false;

for (int n = 0 ; n < ArraySize(LP); n++)

{

if(Symbol() == LP[n])

{

result = true;

}

}

return (result);

}

 
Reason: