//+------------------------------------------------------------------+ //| kjexpert.mq4 | //| Copyright 2019, MOHAMMEDJAFFAR | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MOHAMMEDJAFFAR" #property link "" #property version "1.00" #property strict extern double kj=52; extern int StopLoss=50; extern int TakeProfit=10; extern double lots=0.05; double kijun_sen=iIchimoku(NULL,0,9,kj,52,MODE_KIJUNSEN,1); //<----- semicolon bool isitoktotrade() { int maxorders=1; if(OrdersTotal()<=maxorders) {return true;} else {return false;}; } //****************** bool priceabovekj() { if(iClose(Symbol(),0,1)>kijun_sen && iOpen(Symbol(),0,1)>kijun_sen) { return true; } else {return false;} } //*********************** bool buysetup() { if(iClose(Symbol(),0,1)>kijun_sen && iOpen(Symbol(),0,1)>kijun_sen) { return true; } else {return false;} } //*********************** bool pricebellowkj() { if(iClose(Symbol(),0,1)<kijun_sen && iOpen(Symbol(),0,1)<kijun_sen) { return true; } else {return false;} } //*********************** bool sellsetup() { if(iClose(Symbol(),0,1)<kijun_sen && iOpen(Symbol(),0,1)<kijun_sen) { return true; } else {return false;} } void OnTick() { ///****************BUY************************** if(buysetup()==true) { OrderSend(Symbol(), OP_BUY,lots, Ask, 10*10, Bid-StopLoss*Point*10, Bid+TakeProfit*Point*10, "My 1st Order!"); } ///***************CHEAK IF PRICE IS STILL ABOVE KJ*********************** while(priceabovekj()==true) { }//keep looping until priceabovekj is false ///****************SELL************************** if(sellsetup()==true) { OrderSend(Symbol(), OP_SELL,lots, Ask, 10*10, Bid-StopLoss*Point*10, Bid+TakeProfit*Point*10, "My 1st Order!"); } ///***************CHEAK IF PRICE IS STILL BELLOW KJ*********************** while(pricebellowkj()==true) // <---- function must be pricebellowkj() not pricebellowkjkj() { }//keep looping until pricebellowkj is false }Line 14 and 79, see comments.
Edwin Artunduaga:
This the same cod of mine
-
double kijun_sen=iIchimoku(NULL,0,9,kj,52,MODE_KIJUNSEN,1); //<----- semicolon bool isitoktotrade(){ …
Global and static variables work exactly the same way in MT4/MT5/C/C++.- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants.
There is no
default in MT5 (or MT4 with strict
which you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - Inflation - MQL4 programming forum
-
if(iClose(Symbol(),0,1)>kijun_sen && iOpen(Symbol(),0,1)>kijun_sen) { return true; } else {return false;}
Simplify your code.
Increase Order after stoploss - MQL4 programming forum № 3 -
while(priceabovekj()==true) { }//keep looping until priceabovekj is false
This means you can't use the tester. It also will peg your CPU at max. Do not loop. Return from OnTick and reevaluate on the next tick.
mo798ua:
This the same cod of mine
This the same cod of mine
it is not, see comments in line 14 and 79
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
hi guys i wrote this ea and i have a lot of errors for some reason i dont know i used to define my function outside oftick() errorless but for the first time i get error because defining functions can some one help please