Ride the swap

To add comments, please log in or register
SIMONE MARELLI
322
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?

Syed Oarasul Islam
1533
Syed Oarasul Islam  
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.

SIMONE MARELLI
322
SIMONE MARELLI  
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

Syed Oarasul Islam
1533
Syed Oarasul Islam  
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.

SIMONE MARELLI
322
SIMONE MARELLI  
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

Syed Oarasul Islam
1533
Syed Oarasul Islam  
SIMONE MARELLI:

I have already made it. Everything is ok

Do you see PSwap and NSwap returns more than 1? 

SIMONE MARELLI
322
SIMONE MARELLI  
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
Syed Oarasul Islam
1533
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?  
SIMONE MARELLI
322
SIMONE MARELLI  
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

Syed Oarasul Islam
1533
Syed Oarasul Islam  
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;
}

SIMONE MARELLI
322
SIMONE MARELLI  
Syed Oarasul Islam:

Try this ..

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

12
To add comments, please log in or register