hi im having issue i wrote a function isthereactiveorder() if there is a buy dont open a buy if there is sell dont open sell it seems to not working, if any one can provide any guides i well be thankful
Hello,
need to call first the isthereactiveorder() function and then the cheackmacross(). First check if there are opened orders and then check signals to open new orders.
Next, need to reset canbuy=false and cansell=false on top of OnTick() function.
I have made some change in your code.Hello,
need to call first the isthereactiveorder() function and then the cheackmacross(). First check if there are opened orders and then check signals to open new orders.
Next, need to reset canbuy=false and cansell=false on top of OnTick() function.
Thanks for your reply , i did what you suggest you can check the code again ,nothing changed yet still ton of orders
Thanks for your reply , i did what you suggest you can check the code again ,nothing changed yet still ton of orders
Corrected code...
Corrected code...
great thanks , if you may explain how my logic is wrong i will be thankful
great thanks , if you may explain how my logic is wrong i will be thankful
You set in 2 function 'canbuy' parameter and 'cansell'. isthereactiveorder and cheackmacross are the two functions.
But the correct way is to count buy and sell orders on 'isthereactiveorder ' function. I deleted 'canbuy/cansell' parameters from 'isthereactiveorder ' function, and I set it to calculate orders with new parameters 'CntBuy/CntSell'.
Now, if canbuy = true and CntBuy = 0, then expert open buy orders, same for the sell orders....
- www.mql5.com
You set in 2 function 'canbuy' parameter and 'cansell'. isthereactiveorder and cheackmacross are the two functions.
But the correct way is to count buy and sell orders on 'isthereactiveorder ' function. I deleted 'canbuy/cansell' parameters from 'isthereactiveorder ' function, and I set it to calculate orders with new parameters 'CntBuy/CntSell'.
ok i thought since cansell/canbuy is global variable so any function can access it and change it
ok i thought since cansell/canbuy is global variable so any function can access it and change it
Yes, but isthereactiveorder function cansell/canbuy if there are opened orders turn false, but the cheackmacross function turn they true... cheackmacross function canceled isthereactiveorder function.
If you want to check 2 differents facts (orders and signals) is better to use 2 differents parameters.
- www.mql5.com
- 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 im having issue i wrote a function isthereactiveorder() if there is a buy dont open a buy if there is sell dont open sell it seems to not working, if any one can provide any guides i well be thankful
#property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern double lotsize; extern int ma1 =6; extern int ma2 =18; extern int ma3 =50; extern int ma4 =200; extern double sl=40; extern double tp=80; extern double risk=2; int minbar =ma1; bool canbuy; bool cansell; bool buycross=false; bool sellcross=false; int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { canbuy=false; cansell=false; isthereactiveorder(); cheackmacross(); if(canbuy==true ) { opennew(OP_BUY); } if(cansell==true ) { opennew(OP_SELL); } } void isthereactiveorder(){ for( int i = 0 ; i < OrdersTotal() ; i++ ) { if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) { Print("ERROR - Unable to select the order - ",GetLastError()); break; } if( OrderSymbol()==Symbol() && OrderType() == OP_BUY) canbuy=false; if( OrderSymbol()==Symbol() && OrderType() == OP_SELL) cansell=false; return; } } double calculateLotSize(int stopLoss,int Risk) { // Fetch some symbol properties double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); double minLot = MarketInfo(Symbol(), MODE_MINLOT); double maxLot = MarketInfo(Symbol(), MODE_MAXLOT); double tickVal = MarketInfo(Symbol(), MODE_TICKVALUE); // Calculate the actual lot size double lotSize = AccountBalance() * Risk / 100 / (stopLoss * tickVal); return MathMin( maxLot, MathMax( minLot, NormalizeDouble(lotSize / lotStep, 0) * lotStep ) ); } void opennew(int ordertype){ RefreshRates(); double openprice=0; double closeprice=0; double stopp=0; double takep=0; if(ordertype==OP_BUY){ openprice=Ask; stopp=openprice-(sl*10*Point); takep=openprice+(tp*10*Point); } if(ordertype==OP_SELL){ openprice=Bid; stopp=openprice+(sl*10*Point); takep=openprice-(tp*10*Point); } OrderSend(Symbol(),ordertype ,calculateLotSize(sl*10,risk),openprice,10,NormalizeDouble(stopp,Digits),NormalizeDouble(takep,Digits),NULL,0,0,clrBlue); return; } void cheackmacross(){ double currMA1=iMA(Symbol(),0,ma1,0,MODE_EMA,PRICE_CLOSE,1); double prevMA1=iMA(Symbol(),0,ma1,0,MODE_EMA,PRICE_CLOSE,2); double currMA2=iMA(Symbol(),0,ma2,0,MODE_EMA,PRICE_CLOSE,1); double prevMA2=iMA(Symbol(),0,ma2,0,MODE_EMA,PRICE_CLOSE,2); if(prevMA1>prevMA2 && currMA2>currMA1) { canbuy=true; } if(prevMA1<prevMA2 && currMA2<currMA1) { cansell=true; } }