Okay I am just looking to add a simple stop loss exit to my existing exits.  I 
am a little bit confused as to how to do this because I have several entries 
and exits already.  I realize that their is an example in pyramiding guide 
about adding stop losses, but I cannot figure out how to incorporate that into 
what I already have.

So roughly what I am looking to add is that if I have a loss of x% the trade is 
exited or the trade can be exited based upon the existing rules.  My problem is 
my lack of knowledge in understanding what to do with arrays vs boolean.  I 
could move the exit signals down into the loop, but then I get array boolean 
problems.  Otherwise I do not see how to add a stop loss into the equation 
without putting it into the loop.

I hope my question is not to confusing.  Thank you in advance for the help.

FastMALength = 100;                                                             
                        //Set Fast Moving Average
SlowMALength = 300;                                                             
                        //Set Slow Moving Average

FastMA = DEMA(Close, FastMALength);                                             
        //Fast Moving Average
SlowMA = DEMA(Close, SlowMALength);                                             
        //Slow Moving Average

SetBarsRequired(SlowMALength, 0);
PosQty = 25;
SetOption("MaxOpenPositions", PosQty );
PosMul = 100 / PosQty;
InEquity = PosMul * 1.2;
AddEquity = PosMul * 0.1;
OutEquity = 10;

BuyInc = 5;                                                                     
                                //Incremental Buy Amount (%)
SellInc = BuyInc * 1;
NextBuyARRAY = Null;                                                            
                        //Next Incremental Buy Value
priceatbuy = 0;                                                                 
                        //Initial Buy Value
CounterARRAY = Null;                                                            
                        //Counts Number of Buys
sellCounterARRAY = Null;
NextSellARRAY = Null;

bi = BarIndex();

Cond1 = MA(Volume, 100) > 100000;
Cond2 = OI >= 5;
Cond3 = Cross(FastMA, SlowMA);




//PositionScore = MA(Volume, 100);

Buy =   Cond1 AND Cond2 AND Cond3;                                              
        //Buy Rule #1 - Fast MA Crosses Above Slow MA
Sell = Cross(SlowMA, FastMA) OR bi == LastValue(Ref(bi, -1) ) ;         //Sell 
Rule #1 - Fast MA Crosses Below Slow MA



for (  i =  0;  i < BarCount; i++ )
{

        if(priceatbuy == 0 AND Buy[ i ])
        {
                priceatbuy = BuyPrice[ i ];  //Set inital entry Price
        }
        
                if(priceatbuy > 0)
                {
                
                //Set next BuyPrice
                
                counterARRAY[ i ] = Max( CounterARRAY[ i - 1], 1 + int( ( 
(Close[ i - 1 ] - priceatbuy) / priceatbuy) / (BuyInc/100) ) );
                NextBuyARRAY[ i ] = Max( NextBuyARRAY[ i ], priceatbuy * (1 + 
((BuyInc / 100) * counterARRAY[ i ])));
                sellCounterARRAY[ i ] = Max(sellCounterARRAY[ i - 1], 1 + int( 
( ( NextBuyARRAY[ i ] - Close[ i - 1] ) / NextBuyARRAY[ i ] ) / (SellInc/100) ) 
);
                NextSellARRAY[ i ] = Max( NextSellARRAY[ i ], NextBuyARRAY[ i ] 
* (1 - ((Sellinc / 100) * SellCounterARRAY[ i ] )));

                        if(Close[ i ]  > NextBuyARRAY[ i ])
                        {
                        Buy[ i ] = sigScaleIn;
                        BuyPrice[ i ] = Close[ i ];
                        }
                        
                        if(Close[ i ] < NextSellARRAY[ i ])
                        {
                        Buy[ i ] = sigScaleOut;
                        BuyPrice[ i ] = Close[ i ];
                        }

                
                        
        
                }

                if(Sell[ i ])
                {
                priceatbuy = 0;


                }

PositionScore = CounterARRAY[ i ];
}

Plot(Close, "Price", colorBlack, styleCandle);
Plot(NextBuyARRAY, "NextBuy", colorRed);
Plot(NextSellARRAY, "NextSell", colorBlue);
//PlotOHLC(NextBuyARRAY, NextBuyARRAY, SlowMA, SlowMA, "", colorYellow, 
styleCloud);







SetPositionSize( IIf( Buy == sigScaleIn, InEquity, AddEquity),  
spsPercentOfEquity );
SetPositionSize( OutEquity, IIf( Buy == sigScaleOut, spsPercentOfPosition, 
spsNoChange));


Reply via email to