Want some help with a code.
If an algo takes a long position and lies back 20 points, I want a new position to take too long.
After all, in my manual trade, I usually take 3-4 positions to get in “right”.
Another question.
If my algo takes a long position in DAX with 0.5 contract and I want to open a long position to can I take an even smaller position then?
0.25 contract?
My total position will then be 0.75 contract.
Know that minimum position is 0.5 contract but if you already have a position of 0.5 and add on it then it should work or?
Found this from Vonasi
But, i want to buy if my position go at the wrong way with 20 points.
DEFPARAM CumulateOrders = true
IF not OnMarket and (your conditions) then
Buy 1 contract at market
ENDIF
IF OnMarket and (your conditions) and close > PositionPrice then
Buy 1 contract at market
ENDIF
This code should do the trick..or?
DEFPARAM CumulateOrders = true
POSITIONSIZE=1
// Conditions to enter long positions
IF (my conditions) then
BUY POSITIONSIZE CONTRACTS AT MARKET
ENDIF
if longonmarket and close - tradeprice < 20*pointsize then
buy 1 contract at market
endif
So you want to open a long position and then average down every time price drops at least 20 from your last trade price?
DEFPARAM CumulateOrders = true
POSITIONSIZE=1
// Conditions to enter long positions
IF not onmarket and (my conditions) then
BUY POSITIONSIZE CONTRACTS AT MARKET
ENDIF
if longonmarket and close < tradeprice - 20 then
buy 1 contract at market
endif
As for opening smaller positions after the initial trade. You can only do this if the position size is greater than the minimum position size allowed by your broker. All orders are treated separately and must be at or above the minimum size allowed.
Thanks Vonasi
Suspected that it was so regarding position size.
If I want to limit to a maximum of 1 extra order.
Can i use
Max position = 2 then
DEFPARAM CumulateOrders = true
POSITIONSIZE=1
maxpositions = 2
// Conditions to enter long positions
IF not onmarket and (my conditions) then
BUY POSITIONSIZE CONTRACTS AT MARKET
ENDIF
if longonmarket and close < tradeprice - 20 and countofposition < maxpositions then
buy 1 contract at market
endif
Thanks Vonasi 🙂
Now that you are heated up:)
When I do a back test I see that in the tick mode tab I have a figure of over 50.
I think that is because buy and sell takes place in the same bar.
What is the code to avoid it?
Yes that is because buy and sell takes place in the same bar. The only way to change it is by changing your exit conditions! Perhaps you have a very close stop loss or take profit target? If so then these will look great in back testing but in real life your broker will reject all your orders and your strategy will fall to pieces.