Hi All,
Im rather new here and I want to create a simple system where I look at the high and low of the first 1 hour candle at a start time (in this case 9.00).
If after this first 1 hour the rate goes above the high, than sell. If it goes below the low than sell.
What I did so far is the following:
It doesnt give me an error code but when I run it in the strategy tester, no trades are executed.
Can anyone see what the problem is?
Also Im trying to find a code that closes my trade at the end of each day (at 23.59) no matter what. It seems simple but I tried many things but couldnt find anything.
Thanks for the help!
JB
Hi again,
I actually updated the code as follows:
It looks better but it still doesnt give me any trade (backtesting over the last 6 months on.
Any help?
extern double StoplossPrice; extern double SLPips = 100;; extern double TakeProfitPrice; extern double TPPips = 300; extern double StartHour = 9; extern double StartMinute = 0; extern double StartSecond = 0; extern double FinishHour = 23; extern double FinishMinute = 59; extern double FinishSecond = 0; extern double Pips; extern double Lots = 0.1; extern int Slippage = 3; extern bool UseRR = true; extern double RiskPercent = 2; extern double RewardPercent = 6; extern int Ticketnumber; extern int TicketnumberB; extern int TicketnumberS; extern int TicketnumberCB; extern int TicketnumberCS; extern int FirstAsk; extern int FirstBid; extern double PrevHigh; extern double PrevLow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--FIRST ADJUST FOR A 4 OR 5 DIGIT BROKER------------------- double ticketsize = MarketInfo(Symbol(),MODE_TICKSIZE); if(ticketsize == 0.00001|| Point == 0.0001) Pips = ticketsize*10; else Pips=ticketsize; return(INIT_SUCCEEDED); //--DONT CONTINUE IF NOT ENOUGH MARGIN-------------- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--MONEY MANAEMGEMENT ENTRY--------------------------- double Equity=AccountEquity(); double RiskedAmount = Equity*RiskPercent*0.01; double RewardAmount= Equity *RewardPercent*0.01; // Calculate your max loss & reward per trade double SL=Bid - (RiskedAmount / (Lots*10)*Pips); //ıf one pip is 10 USD... otherwise change the code double TP=Bid + (RewardAmount / (Lots*10)*Pips); if(UseRR)StoplossPrice=SL; else StoplossPrice=Bid-SLPips*Pips; if(UseRR)TakeProfitPrice=TP; else TakeProfitPrice= Bid+TPPips*Pips; //--CHECK FOR OTHER ISSUES (INCL SIGNALS------------------------ if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lots)>=0) // Check if you have enough money in your account if(Hour()== StartHour && Minute()==StartMinute && Seconds()==StartSecond) // Only act if the hour, minute and second on the chart is equal to set parameter if(OrdersTotal()==0) // Only send an order if there is none outstanding TradeSignal(); if(Hour()== FinishHour && Minute()==FinishMinute && Seconds()==FinishSecond) CloseAllTrades(); } void TradeSignal() { Ask == FirstAsk; Bid == FirstBid; High[1] == PrevHigh; Low[1] == PrevLow; if(FirstAsk >PrevHigh) TicketnumberB = OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, StoplossPrice, TakeProfitPrice,NULL); if(FirstBid <PrevLow) TicketnumberS = OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, StoplossPrice, TakeProfitPrice,NULL); } void CloseAllTrades() { if(OrdersTotal()==1) if (OrderType() == OP_BUY) TicketnumberCB = OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, NULL ); if (OrderType() == OP_SELL) TicketnumberCS = OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, NULL ); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
Im rather new here and I want to create a simple system where I look at the high and low of the first 1 hour candle at a start time (in this case 9.00).
If after this first 1 hour the rate goes above the high, than sell. If it goes below the low than sell.
What I did so far is the following:
It doesnt give me an error code but when I run it in the strategy tester, no trades are executed.
Can anyone see what the problem is?
Also Im trying to find a code that closes my trade at the end of each day (at 23.59) no matter what. It seems simple but I tried many things but couldnt find anything.
Thanks for the help!
JB