- Why are you trying to create them each tick? Once in init; the price doesn't matter. Modify them in start.
- If you run on the EURUSD the prices are like 1.23456. That ±30 will not be on the chart.
- Horizontal lines only have one price/time coordinate. You are trying to modify the second.
Your code Documentation double x =iMA( NULL, 0, EMA, 0, MODE_EMA, PRICE_CLOSE, 0 );
double iMA( string symbol, // symbol ENUM_TIMEFRAMES timeframe, // timeframe int ma_period, // MA averaging period int ma_shift, // MA shift ENUM_MA_METHOD ma_method, // averaging method ENUM_APPLIED_PRICE applied_price, // applied price int shift // shift );
- Start using the new Event Handling Functions.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
Thanks for the reply William , you are the best.
I found an easier way, added Envelope Indicator to chart, it solved my problem :)
Now i am trying to put a delay after STOPLOSS hits but when i try to compile it gives the errors below. (btw that code is yours, i found on some other thread :))
int start() { //---- double MaCurrent; int ticket, total; if(Bars<20) { Print("bars less than 20"); return(0); } if(TakeProfit<8) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } MaCurrent=iMA(NULL,0,EMA,0,MODE_EMA,PRICE_CLOSE,0); //... //---- Find my open order, for(int index = OrdersTotal() - 1; index >= 0; index--) if ( OrderSelect(index, SELECT_BY_POS) && OrderMagicNumber() == 34567 || 56789 // with my magic number, && OrderSymbol() == Symbol() ) // in my chart. static datetime newAllowed; newAllowed = TimeCurrent() + 20 * 1; // No new trade until this one closes 20 sec * min if (TimeCurrent() < newAllowed) return(0); // No new trades yet. // Now I can open a new one. total=OrdersTotal(); if(total<1) { // no opened orders identified if(AccountFreeMargin()<(3*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } if(OrdersTotal()>0){ for(i=1; i<=OrdersTotal(); i++) // Checking to make sure there are no open orders. Keep this set to zero unless you want the advisor to open more than one buy at a time or more than one sell at a time. { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available { if(OrderMagicNumber()==34567) {int halt1=1;}///if this magicnumber has an order open... halt! if(OrderMagicNumber()==56789) {int halt2=1;}///if this magicnumber has an order open... halt! } } } // check for long position (BUY) possibility if( (Close[0]-MaCurrent)<=buyfark ) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Stoploss*Point,Bid+TakeProfit*Point,"Scalp",34567,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } // check for short position (SELL) possibility if ((Close[0]-MaCurrent)>=sellfark) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Stoploss*Point,Ask-TakeProfit*Point,"Scalp",56789,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } return(0); } // the end.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to draw 4 horizontal line calculated using a MA but when i run this code, it draw the lines but dosnt update them
What should i do?