good morning everyone
I am trying to test an idea about trend-following trading,
that is to increase/decrease a position with different indicators from those that trigger the open or close of the trade
my idea is to open a position with 5 shares; and then increase or decrease of 1 share, only if an index of 'trendiness' has changed
here is a sample of my thought , for the SP500; the system isn't yet tradeable, it is posted here only for example:
// ---------------------------------------------------
initialcapital=100000 ;
SetOption("InitialEquity", initialcapital );
SetTradeDelays(1,1,1,1);
BuyPrice=SellPrice=CoverPrice=ShortPrice=O;
SetPositionSize( 5, spsShares );
SetPositionSize( 1, IIf( sigScaleIn, spsShares, spsNoChange) );
SetPositionSize( 1, IIf( sigScaleOut, spsShares, spsNoChange) );
MA200=MA(C,200);
MA50= MA(C,50);
MA20= MA(C,20);
MA10= MA(C,10);
MA5= MA(C,5);
RSI2= RSI(2);
index= IIf (C>MA20,2,0) + IIf(C>MA10,1,0) +IIf (C>MA5,1,0) + IIf(RSI2>0.8,1,0) +IIf (RSI2>0.9,1,0) ;
plus = IIf (index > Ref(index,-1), 1, 0);
minus= IIf (index < Ref(index,-1), 1, 0);
Buy= C>MA200 AND C>MA50;
Buy = Buy + sigScaleIn*plus + sigScaleOut*minus ;
Sell= C<MA50;
Short=Cover=0;
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot ( C, "Close", colorBlack , styleCandle );
Plot ( MA200, "ma200", colorBlue , styleLine );
Plot ( MA50 , "ma50", colorRed , styleLine );
Plot ( index , "index", colorAqua, styleOwnScale);
shape = Buy * shapeSmallUpTriangle + Sell * shapeSmallDownTriangle ;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0 , C );
//----------------------------------------------------------------------
the problem is that the system doesn't open with 5 shares...
please there is anybody here to help me?
thanks in advance for any suggestion
kind regards
Appleby
I am trying to test an idea about trend-following trading,
that is to increase/decrease a position with different indicators from those that trigger the open or close of the trade
my idea is to open a position with 5 shares; and then increase or decrease of 1 share, only if an index of 'trendiness' has changed
here is a sample of my thought , for the SP500; the system isn't yet tradeable, it is posted here only for example:
// ---------------------------------------------------
initialcapital=100000 ;
SetOption("InitialEquity", initialcapital );
SetTradeDelays(1,1,1,1);
BuyPrice=SellPrice=CoverPrice=ShortPrice=O;
SetPositionSize( 5, spsShares );
SetPositionSize( 1, IIf( sigScaleIn, spsShares, spsNoChange) );
SetPositionSize( 1, IIf( sigScaleOut, spsShares, spsNoChange) );
MA200=MA(C,200);
MA50= MA(C,50);
MA20= MA(C,20);
MA10= MA(C,10);
MA5= MA(C,5);
RSI2= RSI(2);
index= IIf (C>MA20,2,0) + IIf(C>MA10,1,0) +IIf (C>MA5,1,0) + IIf(RSI2>0.8,1,0) +IIf (RSI2>0.9,1,0) ;
plus = IIf (index > Ref(index,-1), 1, 0);
minus= IIf (index < Ref(index,-1), 1, 0);
Buy= C>MA200 AND C>MA50;
Buy = Buy + sigScaleIn*plus + sigScaleOut*minus ;
Sell= C<MA50;
Short=Cover=0;
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot ( C, "Close", colorBlack , styleCandle );
Plot ( MA200, "ma200", colorBlue , styleLine );
Plot ( MA50 , "ma50", colorRed , styleLine );
Plot ( index , "index", colorAqua, styleOwnScale);
shape = Buy * shapeSmallUpTriangle + Sell * shapeSmallDownTriangle ;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0 , C );
//----------------------------------------------------------------------
the problem is that the system doesn't open with 5 shares...
please there is anybody here to help me?
thanks in advance for any suggestion
kind regards
Appleby
Last edited: