Coding help..How do I get indicator to filter instead of alert? - page 5

[Deleted]  

The orders are being placed too close to the current bid/ask. The orders need to be a certain distance away from the current price. Use Marketinfo function with the stop_level parameter to extract that information and make sure that your orders are that far away from the ask/bid.

Hope this helps.

[Deleted]  
Maji:
The orders are being placed too close to the current bid/ask. The orders need to be a certain distance away from the current price. Use Marketinfo function with the stop_level parameter to extract that information and make sure that your orders are that far away from the ask/bid. Hope this helps.

ummm....

sorry but you lost me there..

can't i just place an order at the 'current' level? most of what I've done to this point has been to execute orders on the close of the period. Can this be done?

I'm going to have to learn what the stop_level parameter and marketinfo functions are first.

thanks for the direction

for whatever it may be worth here is the update I did to the trend bands indicator, that was kinda fun

ok here it is...

Market information identifiers, used with MarketInfo() function.

It can be any of the following values:

MODE_STOPLEVEL 14 Stop level in points.

so I assume it is...

MarketInfo(14)

where do I put it?

or is that...

MarketInfo(NULL,MODE_STOPLEVEL);

or...

double bid =MarketInfo(NULL,MODE_BID);

double ask =MarketInfo(NULL,MODE_ASK);

double point =MarketInfo(NULL,MODE_POINT);

I guess I don't really understand how to use this...can you show me an example?

here is what I'm working with in this case..I wonder why this EA didn't have trouble placing orders before and now it does? It worked before I added the filter???

//----------channel filter

double upLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 0, 0);

double LowLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 2, 0);

// ENTRY

if(total < 2 || isNewSumbol(Symbol())) //I have modified the if condition too: it was total<1 (orBanAway aka cucurucu)

{

double HedgeLots = (HedgePercent/100)*Lots; //calculates the Lots for the hedged position

if(isCrossed == 1 && Ask < upLevel)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### ends here

return(0);

}

if(isCrossed == 2 && Ask > LowLevel)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);

else

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### the added code starts here

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,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());

//###################################################################### ends here

return(0);

}

return(0);

}

return(0);

}

return(0);

}

}

//+------------------------------------------------------------------+
Files:
[Deleted]  

You should use MarketInfo(NULL,MODE_STOPLEVEL) to determine how far your stop orders should be located from the current price. Remeber, it will return its value in pips.

However, you can convert into Points by using something like this:

double MinDist = NormalizeDouble(MarketInfo(NULL,MODE_STOPLEVEL)*Point, Digits);

Now make sure that your stop orders are atleast that far away from the current market price. By the way, by using the NormalizeDouble and Digits, you are converting the pip value to the appropriate places after decimal (4 or 2). That is a very nice thing in MT4.

Hope this helps.

Maji

[Deleted]  
Maji:
You should use MarketInfo(NULL,MODE_STOPLEVEL) to determine how far your stop orders should be located from the current price. Remeber, it will return its value in pips.

However, you can convert into Points by using something like this:

double MinDist = NormalizeDouble(MarketInfo(NULL,MODE_STOPLEVEL)*Point, Digits);

Now make sure that your stop orders are atleast that far away from the current market price. By the way, by using the NormalizeDouble and Digits, you are converting the pip value to the appropriate places after decimal (4 or 2). That is a very nice thing in MT4.

Hope this helps.

Maji

what i don't understand is why adding the indicator as a filter messed up the way it's placing orders or stops. It didn't change any of that as far as I can tell so why does disallowing trades above the line change the way it places it's stop orders?

[Deleted]  

If you don't mind, email me the current code. I will try to take a look at it over the weekend. Can't promise that I will get it fixed but will take an honest look and try.

eli
610
eli  

here is your problem that u should look first

if(isCrossed == 1 && Ask < upLevel-longrange)[/PHP]

Ask and upLevel are in "price" (like 115.56 or 1.2678) while longrange is in pips (like 4,5,6) and u cannot mixed them. U have to normalize the pips to "price" and this is done by muliplying the pips with Points

the corrected code is like that

[PHP]if(isCrossed == 1 && Ask < upLevel-longrange*Point)
[Deleted]  

well for once that's an easy solution...

only...

... thing is I changed it since I made that post. ..I modified the indicator with a parameter to make the bands wider or narrower and took out the part of the EA which made a proximity boundary to the line. I figured that if I could just make the trade bands themselves narrow or wide that would give the same function without being so complex, and for me was easier to keep mental track of....so...

currently it's like this...

//----------channel filter

double upLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 0, 0);

double LowLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 2, 0);

// ENTRY

if(total < 2 || isNewSumbol(Symbol())) //I have modified the if condition too: it was total<1 (orBanAway aka cucurucu)

{

double HedgeLots = (HedgePercent/100)*Lots; //calculates the Lots for the hedged position

if(isCrossed == 1 && Ask < upLevel)

{

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);

else

both ask and uplevel are both in price aren't they? this is the code that is still generating the error. must be more going on..

eli
610
eli  

so far I dont see any problem (code oriented)

But logically, look at this

if(isCrossed == 1 && Ask < upLevel)

You are not checking that they are close, just that the price is lower then the line

eli
610
eli  

I knew I have it!!!

I tests exactly what u wanted to get, and my previuos post I just put the wrong EA.

This EA can check up to 4 TF to check if all of them get the edge at the same time. U can select only one if u want to.

U can use it as an example how to get the logic out of an indicator, and how to combine multiple TF together

regards

Eli

Files:
tbs.mq4  7 kb
[Deleted]  
elihayun:
I knew I have it!!!

I tests exactly what u wanted to get, and my previuos post I just put the wrong EA.

This EA can check up to 4 TF to check if all of them get the edge at the same time. U can select only one if u want to.

U can use it as an example how to get the logic out of an indicator, and how to combine multiple TF together

regards

Eli

this is intriguing I have yet to really expore multi TF indicators but I believe there is merit to them.