ramaParticipant
Senior
//-------------------------------------------------------------------------
// Main code : buy(1)
//-------------------------------------------------------------------------
DEFPARAM FlatBefore = 143500
DEFPARAM FlatAfter = 210000
// Conditions to enter short positions
IF NOT onmarket THEN
sellshort 4 CONTRACTS AT MARKET
ENDIF
nu=12
nn=20222
nn1=200
// Conditions to exit short positions
if countofposition<=7 and countofposition>=4 then
IF longonmarket and close>tradeprice-nu THEN
sellshort 3 CONTRACTS AT tradeprice-nu stop
endif
endif
if countofposition<=9 and countofposition>=7 then
IF longonmarket and close>tradeprice-nu THEN
sellshort 2 CONTRACTS AT tradeprice-nu stop
endif
endif
if countofposition<=10 and countofposition>=9 then
IF longonmarket and close>tradeprice-nu THEN
sellshort 1 CONTRACTS AT tradeprice-nu stop
endif
endif
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
if onmarket and (floatingprofit <=-nn or floatingprofit >= nn1) then
exitshort at market
endif
I want to sell 10 contacts first 4 at market then 3 , 2, 1 at last trade price – nu, this code is not working for shortpostions, where the long position code is working fine where i replaced just close<tradprice+nu then, what is wrong with this code?
ramaParticipant
Senior
//-------------------------------------------------------------------------
// Main code : buy
//-------------------------------------------------------------------------
DEFPARAM FlatBefore = 143500
DEFPARAM FlatAfter = 210000
// Conditions to enter short positions
IF NOT onmarket THEN
buy 4 CONTRACTS AT MARKET
ENDIF
nu=12
nn=20222
nn1=200
// Conditions to exit short positions
if countofposition<=7 and countofposition>=4 then
IF longonmarket and close<tradeprice+nu THEN
buy 3 CONTRACTS AT tradeprice+nu stop
endif
endif
if countofposition<=9 and countofposition>=7 then
IF longonmarket and close<tradeprice+nu THEN
buy 2 CONTRACTS AT tradeprice+nu stop
endif
endif
if countofposition<=10 and countofposition>=9 then
IF longonmarket and close<tradeprice+nu THEN
buy 1 CONTRACTS AT tradeprice+nu stop
endif
endif
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
if onmarket and (floatingprofit <=-nn or floatingprofit >= nn1) then
sell at market
endif
Change LONGONMARKET to SHORTONMARKET?
rama – Please give your topics more meaningful titles otherwise we end up with a forum full of meaningless ‘code is not working’ topics. I have edited your topic title.
You need it as below (If shortonmarket, countofposition <= –7 etc …
not tested though
if countofposition<= -7 and countofposition>=-4 then
IF shortonamrket and close>tradeprice-nu THEN
sellshort 3 CONTRACTS AT tradeprice-nu stop
endif
Yeah it works! 🙂
CountofPosition of Shorts need a – / minus so – 4, -7 etc
DEFPARAM FlatBefore = 143500
DEFPARAM FlatAfter = 210000
// Conditions to enter short positions
IF NOT onmarket THEN
sellshort 4 CONTRACTS AT MARKET
ENDIF
nu=12
nn=20222
nn1=200
// Conditions to exit short positions
if countofposition>= -7 and countofposition<= -4 then
IF shortonmarket and close>tradeprice-nu THEN
sellshort 3 CONTRACTS AT tradeprice-nu stop
endif
endif
if countofposition>= -9 and countofposition<= -7 then
IF shortonmarket and close>tradeprice-nu THEN
sellshort 2 CONTRACTS AT tradeprice-nu stop
endif
endif
if countofposition>= -10 and countofposition<= -9 then
IF shortonmarket and close>tradeprice-nu THEN
sellshort 1 CONTRACTS AT tradeprice-nu stop
endif
endif
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
if onmarket and (floatingprofit <=-nn or floatingprofit >= nn1) then
exitshort at market
endif
Well spotted GraHal – I didn’t spot that COUNTOFPOSITION was not shown as negative for short positions. You’re getting pretty good at this code analysis!