Hi,
I want to visualize my Entry and Exitpoints.
(see the code below)
// Insidebar; Farbe egal
b = Ref(H,-1) < Ref(H,-2) AND Ref(L,-1) > Ref(L,-2) ;
InsidebarLong = b ;
k = Ref(H,-1) < Ref(H,-2) AND Ref(L,-1) > Ref(L,-2) ;
InsidebarShort = k ;
TradeDelay = 0; // set it to 0 for no delays
SetTradeDelays( TradeDelay, TradeDelay, TradeDelay, TradeDelay );
TickSize = 0.01;
// sample entry rules
// Equity(1); // THIS EVALUATES STOPS
BuyPrice = Max(Ref(H,-1) , Open) ;
SellPrice = Open ;
ShortPrice = Min(Ref(L,-1) , Open) ;
CoverPrice = Open ;
// Long //
Buy = InsidebarLong AND H > Ref(H,-1);
stopLevelLong = Ref( L, -1 ); // use previous bar low // define stop level
stopAmountLong = BuyPrice - stopLevelLong + 0.05*(Ref(ATR(14),-1)); // calculate stop amount
stopAmountLong = Max( TickSize, BuyPrice - stopLevelLong ); // make sure stop-amount is at least one tick
Sell = 0 ;
// Short
Short = InsidebarShort AND L < Ref(L,-1) ;
stopLevelShort = Ref( H, -1 ); // use previous bar high // define stop level
stopAmountShort = stopLevelShort - ShortPrice + 0.05*(Ref(ATR(14),-1)); // calculate stop amount
stopAmountShort = Max( TickSize, stopLevelShort - ShortPrice ); // make sure stop-amount is at least one tick
Cover = 0 ;
// assign stop amount conditionally by checking if there is a Buy signal on given bar
IsLong = Ref( Buy, -TradeDelay );
stopAmount = IIf( IsLong, stopAmountLong, stopAmountShort );
IsShort = Ref(Short, -TradeDelay) ;
stopAmount = IIf( IsShort, stopAmountShort, stopAmountLong );
Risk = 1; // Risk in %
U = Risk/100 ; // umgewandelt in %
InitialEquity = 100000 ;
Z = U * InitialEquity ; // realtives --> absolutes Risiko
SetOption("InitialEquity", 100000 ); // set initial equity = 100K
TickSize = 0.01 ;
TickValue = 0.01 ;
MarginDeposit = 100 ;
PointValue = TickValue / TickSize ;
size = Z/(stopAmount*(TickValue/TickSize)) ; // Z = size*stopAmount
SetPositionSize( size, spsShares ); // number of shares/contracts per trade
ApplyStop( stopTypeLoss, stopModePoint, stopAmountShort, True );
ApplyStop( stopTypeProfit, stopModePoint, 1*stopAmountShort, True );
PlotShapes( IIf(Buy, shapeCircle, shapeNone),colorBrightGreen, 0, BuyPrice, 0 );
// problem with this one, it couldn't work
PlotShapes( IIf(Sell, shapeCircle, shapeNone),colorRed, 0, SellPrice, 0 );
If I have my Buy-Condition and BuyPrice then it's no problem, but
what's when Sell = 0; SellPrice = Open (e.g.) and I'm using ApplyStop?
Must I write the ApplyStop, like I did in the following formula, into the sell-array and into the SellPrice ?
I tried it, but it doesn't work like it should. (see below)
Isn't it possible to write the applystop into the sell-array and SellPrice ?
Need some help.
// Insidebar; Farbe egal
b = Ref(H,-1) < Ref(H,-2) AND Ref(L,-1) > Ref(L,-2) ;
InsidebarLong = b ;
k = Ref(H,-1) < Ref(H,-2) AND Ref(L,-1) > Ref(L,-2) ;
InsidebarShort = k ;
TradeDelay = 0; // set it to 0 for no delays
SetTradeDelays( TradeDelay, TradeDelay, TradeDelay, TradeDelay );
TickSize = 0.01;
// sample entry rules
// Long //
Buy = InsidebarLong AND H > Ref(H,-1);
BuyPrice = Max(Ref(H,-1) , Open) ;
stopLevelLong = Ref( L, -1 ); // use previous bar low // define stop level
stopAmountLong = BuyPrice - stopLevelLong + 0.05*(Ref(ATR(14),-1)); // calculate stop amount
stopAmountLong = Max( TickSize, BuyPrice - stopLevelLong ); // make sure stop-amount is at least one tick
// Zwischeneinschub
Equity(1,0) ; // evaluate stops, all quotes
// intradeLong = Flip(Buy , Sell); // True when Buy, False when Sell
// SetOption("EveryBarNullCheck", True) ; // checks for null bars
// intradeShort = Flip(Short, Cover); // True when Short; False when Cover
StopLevel_Buy = ValueWhen(Buy, BuyPrice - stopAmountLong) ;
TargetLevel_Buy = ValueWhen(Buy, BuyPrice + 1*stopAmountLong) ;
Stop_Buy = Cross(L, StopLevel_Buy) ;
Target_Buy = Cross(H, TargetLevel_Buy) ;
Sell = Stop_Buy OR Target_Buy ;
// intradeLong = Flip(Buy , Sell); // True when Buy, False when Sell
SellPrice = IIf(Stop_Buy, StopLevel_Buy, IIf(Target_Buy, TargetLevel_Buy, 0)) ;
// Short
Short = InsidebarShort AND L < Ref(L,-1) ;
ShortPrice = Min(Ref(L,-1) , Open) ;
stopLevelShort = Ref( H, -1 ); // use previous bar high // define stop level
stopAmountShort = stopLevelShort - ShortPrice + 0.05*(Ref(ATR(14),-1)); // calculate stop amount
stopAmountShort = Max( TickSize, stopLevelShort - ShortPrice ); // make sure stop-amount is at least one tick
Cover = 0 ;
CoverPrice = Open ;
// assign stop amount conditionally by checking if there is a Buy signal on given bar
IsLong = Ref( Buy, -TradeDelay );
stopAmount = IIf( IsLong, stopAmountLong, stopAmountShort );
IsShort = Ref(Short, -TradeDelay) ;
stopAmount = IIf( IsShort, stopAmountShort, stopAmountLong );
Risk = 1; // Risk in %
U = Risk/100 ; // umgewandelt in %
InitialEquity = 100000 ;
Z = U * InitialEquity ; // realtives --> absolutes Risiko
SetOption("InitialEquity", 100000 ); // set initial equity = 100K
TickSize = 0.01 ;
TickValue = 0.01 ;
MarginDeposit = 100 ;
PointValue = TickValue / TickSize ;
size = Z/(stopAmount*(PointValue/TickSize)) ; // Z = size*stopAmount
SetPositionSize( size, spsShares ); // number of shares/contracts per trade
PlotShapes( IIf(Buy, shapeCircle, shapeNone),colorBrightGreen, 0, BuyPrice, 0 );
PlotShapes( IIf(Sell, shapeCircle, shapeNone),colorRed, 0, SellPrice, 0 );