Close All Trades (Long and Short)

Posted By: Qw3rty

Close All Trades (Long and Short) - 07/18/20 02:14

I am wanting to hedge my positions using a single asset (Hedge = 2;)

Is there a way to close all trades (both long and short) when a certain condition is met.

I have tried the following with the "if statement" on the outside as well.
for(open_trades)
{
if(condition)
exitLong();
exitShort();

}

This seems to only close long trades.

I read on the forum about using the tick() function but no luck either.

I have tried using functions like a portfolio but no luck.

Any ideas?
Posted By: danatrader

Re: Close All Trades (Long and Short) - 07/18/20 07:44

for(open_trades)
{
if(condition){
exitLong();
exitShort();
}
}
Posted By: Qw3rty

Re: Close All Trades (Long and Short) - 07/18/20 10:46

Originally Posted by danatrader
for(open_trades)
{
if(condition){
exitLong();
exitShort();
}
}


This is awesome, thanks for the update. That makes sense.
Posted By: Grat

Re: Close All Trades (Long and Short) - 07/19/20 11:21

so, i thinking this:
Code
for(open_trades)
{
if(condition){
exitLong();
exitShort();
}
}


is the same like
Code
if(condition){
exitLong();
exitShort();
}


Exits all long or all short trades that match the given filter condition (see below), at market or at a given price limit, until the given number of lots is closed.
Posted By: Qw3rty

Re: Close All Trades (Long and Short) - 07/20/20 09:17

Just tested and can confrim the output is th same with either choice of code. No need for a loop then.
© 2024 lite-C Forums