Ride the swap

 

Hello,


i have made a bot that calculate the swap for long and short, using 


double PSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_LONG);

double NSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_SHORT);


they return the correct value, but i don't know why i try to make a code like that:


if( PSwap > 1 ...)

if (NSwap > 1...)


code has no effect. Why? Where am i wrong?

 
SIMONE MARELLI:

Hello,


i have made a bot that calculate the swap for long and short, using 


double PSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_LONG);

double NSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_SHORT);


they return the correct value, but i don't know why i try to make a code like that:


if( PSwap > 1 ...)

if (NSwap > 1...)


code has no effect. Why? Where am i wrong?

You have not mentioned what do you want to do with these lines..

if( PSwap > 1 ...)

if (NSwap > 1...)


If you do not have any open orders then it should do nothing. If you are using strategy tester then make sure your bot first places some orders and then you can use those swap values if the orders have swaps applied already.

 
Syed Oarasul Islam:

You have not mentioned what do you want to do with these lines..

if( PSwap > 1 ...)

if (NSwap > 1...)


If you do not have any open orders then it should do nothing. If you are using strategy tester then make sure your bot first places some orders and then you can use those swap values if the orders have swaps applied already.

I want to let an ea to open positions only if swap is positive (if it's posive for a buy, just open buy, if it's positive for the sell, just open sell)

So i have wrote a bool,


Sell = false;

Buy = false;

if( PSwap > 1 )

Buy true

if (NSwap > 1)

Sell true


it's of course not the real code, just to let you understand, but bool has no value, it still open in sell and buy

 
SIMONE MARELLI:

I want to let an ea to open positions only if swap is positive (if it's posive for a buy, just open buy, if it's positive for the sell, just open sell)

So i have wrote a bool,


Sell = false;

Buy = false;

if( PSwap > 1 )

Buy true

if (NSwap > 1)

Sell true


it's of course not the real code, just to let you understand, but bool has no value, it still open in sell and buy

Attach this line in your bot ..

Comment("Long Swap: "+PSwap + "Short Swap: "+ NSwap+ "SELL: "+ Sell+ "BUY: "+Buy);

You should observe the values in the comment and then check if your conditions are really met. If Sell returns 0 then most likely NSwap returning 0. Likewise if Buy returns 0 the PSwap returning 0.

 
Syed Oarasul Islam:

Attach this line in your bot ..

Comment("Long Swap: "+PSwap + "Short Swap: "+ NSwap+ "SELL: "+ Sell+ "BUY: "+Buy);

You should observe the values in the comment and then check if your conditions are really met. If Sell returns 0 then most likely NSwap returning 0. Likewise if Buy returns 0 the PSwap returning 0.

I have already made it. Everything is ok

 
SIMONE MARELLI:

I have already made it. Everything is ok

Do you see PSwap and NSwap returns more than 1? 

 
Syed Oarasul Islam:

Do you see PSwap and NSwap returns more than 1? 

Yes, check. But if i use the bool, doesn't have effect

Files:
Cattura.PNG  3 kb
 
Is Auto Trading turned on? if not turn on please. Otherwise you might have problem with your order open code. Did you check the journal?  
 
Syed Oarasul Islam:
Is Auto Trading turned on? if not turn on please. Otherwise you might have problem with your order open code. Did you check the journal?  

lol of course is on. I have tested in strategy tester and on live chart, in every case it open both, buy and sell, without considering the bool

 
SIMONE MARELLI:

lol of course is on. I have tested in strategy tester and on live chart, in every case it open both, buy and sell, without considering the bool

Try this ..

static bool Sell = false;

static bool Buy = false;

double PSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_LONG);

double NSwap = SymbolInfoDouble(Symbol(),SYMBOL_SWAP_SHORT);

if( PSwap > 1 {
Buy=true;
Sell=false;
}

if (NSwap > 1){
 Sell=true;
 Buy=false;
}

 
Syed Oarasul Islam:

Try this ..

I have tried, always same problem, is getting me crazy 

Reason: