help on iCustom, error calling 1 buffer - page 3

 
Adebayo Samson Adewuyi #:
Thanks for your input I appreciate that, firstly I will try and print it out as you have suggested, have tried the Getlasterror function before but it doesn't bring out any error, I will make use of your advice now 
Secondly, even if I removed the Buy conditions totally and I'm left with just the lines for Sell, it will still do the same, and if the Sell lines comes first and the Buy is after, it's still same issue.
Lastly, trades are closed due to Sl or Tp no extra function to close trades 

Thanks once again 

So you have no other OrderClose() feature other then sl and tp ? 
No OrderCloseBy() or anything just sl tp only ? 

What happens when the indicator moves in the opposite direction ? Do you just let it ride until it hits the sl ? Regardless of the reversal of the indicator ? 

Please confirm again that you have no other OrderClose() in your code and only way the OrderClose() is when sl and tp ONLY ? 

Can you not post the entire code ? Use the (Alt+S) OR Code feature of the forum that is specifically for posting your code to this forum ?  
We need to see it. 

Additionally we need to see your logs in the terminal. What does the terminal say when the Order is closed and why ? Does it say that it's closed due to sl or tp ? OR something else ? 

We need to see this too. 


Then don't forget to Print("k =", k);  This will return k for your to see in your terminal every time Buy, and Sell k will be true or false. 
The using the Print call to return things in your terminal will tell you a lot so you can see what is happening. 

 
Not at all, I don't have any other functions to close trade except for the Sl and TP.
And that's the full code from the Ontick function.
When I started having this issue that's why I wrote a short code lines just to see if it was the other source having the issue but no it's all
Infact I just reinstall my mt4 and same issue 

Please if you have a good arrow indicator which you have tested and works well please send let me test with that to see where the problem is coming from, if it will work well here or not
I will also try your suggestions too

Thanks 
 
Adebayo Samson Adewuyi #:
Not at all, I don't have any other functions to close trade except for the Sl and TP.
And that's the full code from the Ontick function.
When I started having this issue that's why I wrote a short code lines just to see if it was the other source having the issue but no it's all
Infact I just reinstall my mt4 and same issue 

Please if you have a good arrow indicator which you have tested and works well please send let me test with that to see where the problem is coming from, if it will work well here or not
I will also try your suggestions too

Thanks 

So what does the terminal say is the reason for the trade being closed ? 

Does it say Sell Order opened then show you that SL was hit or does it say there was an error opening the trades ? 
Can you post a snip of your terminal output from the "Experts" Tab ? 

This tab should tell you why the orders are opening and closing etc. 

 
Another problem with your code is the variable type
bool k =OrderSend() in your code

According to the docs OrderSend() is an int type. 

So you might change this to 
int k=OrderSend()

Otherwise you will get an error in the terminal expressing to check your return code. 

You need to do this and test in the tester or in your demo account and read the terminal outputs. 

You have an error with opening orders. 

0 19:23:03.528 2023.06.22 07:58:26  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:28  indicator_test EURUSD,M5: Error opening BUY order : 0
0 19:23:03.528 2023.06.22 07:58:28  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:30  indicator_test EURUSD,M5: Error opening BUY order : 0
0 19:23:03.528 2023.06.22 07:58:30  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:31  indicator_test EURUSD,M5: Error opening BUY order : 0


Some sell orders are opening and being terminated by sl or tp but others are simply errors. 

The error ones that you see on your chart or tester will say "closed by tester" 

closed by tester

When the market data feed opens tomorrow I'll test in the demo some more. 

I edited your code this way to get error returns. 

//---
   //---
   if(iCustom(Symbol(),0,"indicator",0,1)<Low[1]) // 0 is the buffer that I want a buy order and it works perfetly
      if(OrdersTotal()==0)
         int k = OrderSend(Symbol(),OP_BUY,0.01,Ask,500,Bid-100*Point,Bid+100*Point,Symbol(),333,0,Blue);
         Print("Error opening BUY order : ",GetLastError());


   if(iCustom(Symbol(),0,"indicator",1,1)>High[1])// 1 is the buffer for the sell condition but picks trades on every close of another
      if(OrdersTotal()==0)
         int k = OrderSend(Symbol(),OP_SELL,0.01,Bid,500,Ask+100*Point,Ask-100*Point,Symbol(),333,0,Red);
         Print("Error opening SELL order : ",GetLastError());
 


/// I ony use one condition at a time because of OrdersTotal()==0
 
This code is not Buying any orders on my end. 

Only sell orders with sl and tp but not buying. 
 
I made some edits and there are no buy/sell errors in the tester.

I'll let it run on the demo over night which seems to be working without errors now, but the tester shows only buys and no sells. I am not sure why yet, but will mess it some more tomorrow to learn from this myself. 

However, the demo seems to be selling. 
   //---
   if(iCustom(Symbol(),0,"indicator",0,1)<Low[1]) // 0 is the buffer that I want a buy order and it works perfetly
      {
      if(OrdersTotal()==0)
         { 
         int k = OrderSend(Symbol(),OP_BUY,0.01,Ask,500,Bid-100*Point,Bid+100*Point,Symbol(),333,0,Blue);
         Print("Error opening BUY order : ",GetLastError());
         Print("Orders Total Low ", OrdersTotal());
         }
       }
       else return;
       
   if(iCustom(Symbol(),0,"indicator",1,1)>High[1])// 1 is the buffer for the sell condition but picks trades on every close of another
      {
      if(OrdersTotal()==0)
         {
         int k = OrderSend(Symbol(),OP_SELL,0.01,Bid,500,Ask+100*Point,Ask-100*Point,Symbol(),333,0,Red);
         Print("Error opening SELL order : ",GetLastError());
         Print("Orders Total High ", OrdersTotal());
         }
       }
       else return;
  Print ("iCustom Low ", iCustom(Symbol(),0,"indicator",0,1)<Low[1]);
  Print ("iCustom High ", iCustom(Symbol(),0,"indicator",1,1)>High[1]);
  Print("Orders Total OnTick ", OrdersTotal());

/// I ony use one condition at a time because of OrdersTotal()==0
 
Agent86 #:

So what does the terminal say is the reason for the trade being closed ? 

Does it say Sell Order opened then show you that SL was hit or does it say there was an error opening the trades ? 
Can you post a snip of your terminal output from the "Experts" Tab ? 

This tab should tell you why the orders are opening and closing etc. 

Hi,

yes it close trades due to stoploss and takeprofit

Files:
Capture.PNG  58 kb
 
Agent86 #:
Another problem with your code is the variable type
bool k =OrderSend() in your code

According to the docs OrderSend() is an int type. 

So you might change this to 
int k=OrderSend()

Otherwise you will get an error in the terminal expressing to check your return code. 

You need to do this and test in the tester or in your demo account and read the terminal outputs. 

You have an error with opening orders. 

0 19:23:03.528 2023.06.22 07:58:26  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:28  indicator_test EURUSD,M5: Error opening BUY order : 0
0 19:23:03.528 2023.06.22 07:58:28  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:30  indicator_test EURUSD,M5: Error opening BUY order : 0
0 19:23:03.528 2023.06.22 07:58:30  indicator_test EURUSD,M5: Error opening SELL order : 0
0 19:23:03.528 2023.06.22 07:58:31  indicator_test EURUSD,M5: Error opening BUY order : 0


Some sell orders are opening and being terminated by sl or tp but others are simply errors. 

The error ones that you see on your chart or tester will say "closed by tester" 



When the market data feed opens tomorrow I'll test in the demo some more. 

I edited your code this way to get error returns. 

I tried to print out the error to, I have same results 0
I think 0 means no error, so if that we no error with our ordersend 

 
Agent86 #:
I made some edits and there are no buy/sell errors in the tester.

I'll let it run on the demo over night which seems to be working without errors now, but the tester shows only buys and no sells. I am not sure why yet, but will mess it some more tomorrow to learn from this myself. 

However, the demo seems to be selling. 

The reason why you have no sell here is "retun"

if(iCustom(Symbol(),0,"indicator",0,1)<Low[1]) // 0 is the buffer that I want a buy order and it works perfetly
     {
      if(OrdersTotal()==0)
        {
         int k = OrderSend(Symbol(),OP_BUY,0.01,Ask,500,Bid-100*Point,Bid+100*Point,Symbol(),333,0,Blue);
         Print("Error opening BUY order : ",GetLastError());
         Print("Orders Total Low ", OrdersTotal());
        }
     }
   else
     return; // this line will terminate and return back
 
Agent86 #:
I made some edits and there are no buy/sell errors in the tester.

I'll let it run on the demo over night which seems to be working without errors now, but the tester shows only buys and no sells. I am not sure why yet, but will mess it some more tomorrow to learn from this myself. 

However, the demo seems to be selling.
Adebayo Samson Adewuyi #:
Not at all, I don't have any other functions to close trade except for the Sl and TP.
And that's the full code from the Ontick function.
When I started having this issue that's why I wrote a short code lines just to see if it was the other source having the issue but no it's all
Infact I just reinstall my mt4 and same issue 

Please if you have a good arrow indicator which you have tested and works well please send let me test with that to see where the problem is coming from, if it will work well here or not
I will also try your suggestions too

Thanks 

Somehow the Print function is getting suppressed so I can't diagnose this any further. 

Your iCustom comparisons are always true that much I know.
I'm not sure if this is why there is some conflict in milliseconds for the Print function that is not being read by the terminal or something else. 

I can comment/omit your comparisons and Print function calls anything I want as it should, but when inserting your code only a few lines of Print calls can be read, and NO print calls withing the code block comparison are being read not even the GetLastError. 

GetLastError does read in the tester but not the print calls. I'm not sure why.