Using Stop loss or custom EL code to reverse with extras

Questions about MultiCharts and user contributed studies.
User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Using Stop loss or custom EL code to reverse with extras

Postby Mobiius » 30 Mar 2010

Hi.

I'd like to go a little further with the basic Stop Loss Signal.

As of now it stops out my futures contracts and then it will wait for another signal to enter a position again.

I'd like to be able to:

1. upon stop @ set amount reverse and double the position.
2. set a new stop loss for this position.
3. set a new profit target for this position.

can anyone tell me how to do this within the Stop Loss signal, or would i need to code a completely different signal?

Cheers.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 30 Mar 2010

don't use stoploss.

if you are LONG 1 contract,

the SELLSHORT command will automatically :

a. liquidate your 1 long position,
b. enter 1 short position.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 30 Mar 2010

I see, so instead of a stop loss signal i should make a custom signal that:

1. figures out if it is in a long or short position currently.
2. at a set loss amount (say $1000) it sellshort or is 'buy' the opposite equivalent?
3. then set another stop loss for this position.
4. set a profit target for this position.

So it's basically programming a new signal, no?

I guess i have to wip out my EL essential book when i was with TS...

geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

Postby geektrader » 30 Mar 2010

Here is a basic StopAndReverse that I´ve coded. Maybe it´s a starting point for you:

Code: Select all

input: StopAndReverseDollar(500);


If MarketPosition=1 and positionprofit < -StopAndReverseDollar then Sell Short ("StopAndReverseL") Next Bar at Market;
If MarketPosition=-1 and positionprofit < -StopAndReverseDollar then Buy ("StopAndReverseS") Next Bar at Market;

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 30 Mar 2010

thanks for the starting code.. i was not able to get mine going. ill try yours.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 30 Mar 2010

gt:

I'm having trouble differentiating the reversal (one time) trade from the rest.

What i mean is once this reversal is taken (and it seems to work fine in that regard, I need to have a stoploss of $1000 lets say. Unfortunatly when the StopAndReverseDollar amount is hit ($at 500 presently) then it reverses again.

I want this to be a once shot trade. If it fails @ a stop of $1000 then it is out, if it has a profit of $2000 then it is out too unless the overall strategy gives a signal and re-instates itself.

Also, I am having trouble 'doubling' the position. So if you have 1 long and this is activated then you have 2 short.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 30 Mar 2010

I know I'm asking alot here so I will try to be clear and I REALLY appreciate the help in advanced for people who are willing.

I will try and break it down so it is clear:

1. First use code such as :

Code: Select all

input: StopAndReverseDollar(500);


If MarketPosition=1 and positionprofit < -StopAndReverseDollar then Sell Short ("StopAndReverseL") Next Bar at Market;
If MarketPosition=-1 and positionprofit < -StopAndReverseDollar then Buy ("StopAndReverseS") Next Bar at Market;
2. But, Double the position (if one long, then 2 short).

3. And, Have a stop loss just for this trade of $X.

4. And, Have a Profit Target just for this trade of $X.

5. And, If original strategy calls to be back in a position then cancel this strategy and run the original strategy (if 2 short, then one long for example again).

I have all the time in the world as I know if I don't get help here then I will have to pay my programmer :-) Which I do not mind doing, he is worth it. And besides, I'm still trying to test the autotrading through IB. It's taking a bit longer than i expected for the TS to IB/MC change...


Cheers.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 30 Mar 2010

Ah.. one work around I found is to create a data1-data2

so

Code: Select all

[IntrabarOrderGeneration = false]
input: StopAndReverseDollar(670);


If (data1) MarketPosition=1 and (data1) positionprofit < -StopAndReverseDollar then Sell Short 2 contracts (data2) ("StopAndReverseL") Next Bar at Market;
If (data1) MarketPosition=-1 and (data1) positionprofit < -StopAndReverseDollar then Buy 2 contracts (data2) ("StopAndReverseS") Next Bar at Market;
This code obviously doesn't work...

But from here i should be able to set a stop loss and profit target that is just for data 2.

thanks again in advance.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 30 Mar 2010

autotrade is for data1 only.


(at least for now. data2 is on the list for future releases).

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 30 Mar 2010

I know I'm asking alot here so I will try to be clear and I REALLY appreciate the help in advanced for people who are willing.

I will try and break it down so it is clear:
...
Cheers.
I would suggest you to draw a flow chart...
with branches for all the permutations.

you can then use the flow chart to visualize your logic.

coding with EasyLanguage is not difficult,
it is just tedious.

.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 31 Mar 2010

good suggestion, i can see how that will help. i will do that then post it for some help. thanks.

User avatar
Mobiius
Posts: 60
Joined: 11 Mar 2010
Location: Victoria, BC, Canada
Has thanked: 4 times

Postby Mobiius » 31 Mar 2010

yaaa.... I ended up sending my 3 page notes away to my programmer... just easier this way... and quicker :-)

thanks again.


Return to “MultiCharts”