code_1
code_1
0 at
https://mozilla.org/MPL/2.0/
// © TradeWiseWithEase
//@version=5
indicator("BE - Golden Cross Crude Key",shorttitle = "BE-CRUDE-V0.1.1", overlay =
true)
import TradeWiseWithEase/BE_CustomFx_Library/93 as BEL
if barstate.isconfirmed
if NxtTrend_Direction == -1
MaxLowPrice := math.max(LowPrice, MaxLowPrice)
if HighMovAvg < MaxLowPrice and close < nz(low[1], low) and (Sensitivity <
1 or (Sensitivity >= 1 and (MaxLowPrice - close) > SMAofATR * 1.75))
Trend_Direction := -1
NxtTrend_Direction := 1
MinHighPrice := HighPrice
else if ConvertHT2Short and Sensitivity >= 1
Trend_Direction := -1
NxtTrend_Direction := 1
MinHighPrice := HighPrice
else
MinHighPrice := math.min(HighPrice, MinHighPrice)
if LowMovAvg > MinHighPrice and close > nz(high[1], high) and (Sensitivity
< 1 or (Sensitivity >= 1 and (close - MinHighPrice) > SMAofATR * 1.75))
Trend_Direction := 1
NxtTrend_Direction := -1
MaxLowPrice := LowPrice
else if ConvertHT2Long and Sensitivity >= 1
Trend_Direction := 1
NxtTrend_Direction := -1
MaxLowPrice := LowPrice
if Trend_Direction == 1
if Trend_Direction[1] == -1 and not na(Trend_Direction[1])
CapUp := na(CapDown[1]) ? CapDown : CapDown[1]
else
CapUp := na(CapUp[1]) ? MaxLowPrice :
math.max(MaxLowPrice, CapUp[1])
else
if Trend_Direction[1] == 1 and not na(Trend_Direction[1])
CapDown := na(CapUp[1]) ? CapUp : CapUp[1]
else
CapDown := na(CapDown[1]) ? MinHighPrice :
math.min(MinHighPrice, CapDown[1])
plot(
ShowTrendTracker ? TrendLevel : na,
title = "Trend Tracker",
linewidth = Tr_LineWidth,
color = TrendColor,
editable = false)
//#endregion
//#endregion
//#region EntrySetups
if HasCrossOverHappened
LongSetup.ToBreakValue := high + 5
LongSetup.CrossCandle := bar_index + 1
LongSetup.MaxToTradeCandle := bar_index + 2
LongSetup.SLForTheTrade := Log.T_HasEntered == 1 and
Log.T_Direction == -1 and bar_index > Log.NextTradeAfter ? high : na
Log.ExitCandleCheck := if not na(LongSetup.SLForTheTrade)
bar_index
if HasCrossUnderHappened
ShortSetup.ToBreakValue := low - 5
ShortSetup.CrossCandle := bar_index + 1
ShortSetup.MaxToTradeCandle := bar_index + 2
ShortSetup.SLForTheTrade := Log.T_HasEntered == 1 and
Log.T_Direction == 1 and bar_index > Log.NextTradeAfter ? low : na
Log.ExitCandleCheck := if not na(ShortSetup.SLForTheTrade)
bar_index
LongTadeEntry = false
ShortTadeEntry = false
Log.T_Symbol := ScriptName
array.clear(MainLegSymbols)
for [index, value] in ListOfTradingAccount
Otype = value == "TRADINGVIEW" ?
"" : "L"
[Symbol_T, AlertString_T] =
BEL.LegScriptContructor(FutOrOps == "OPS" ? true : false, IAO, deepness,
StrikeDiff,
true, "C", 0.0, 0.75, "NLB", FutOrOps == "OPS" ?
array.get(ListOfOptionsPrefix, index) : array.get(ListOfFuturePrefix, index), 0,
"BUY", Log.T_QtyString, "", "", value, "MCX", Otype, true, "0.1%")
array.push(MainLegSymbols, Symbol_T)
array.push(EntryAlertLegsArray, AlertString_T)
FinalEntryAlertText :=
BEL.LegConstructor(EntryAlertLegsArray, "NLB")
if str.length(FinalEntryAlertText) > 3
alert(FinalEntryAlertText, alert.freq_once_per_bar)
Log.T_En_Date_Time := DateTimeString
Log.T_EnCandle := bar_index
Log.T_Name := "Long | Cross Over Trade
on " + Log.T_Symbol
Log.T_HasEntered := 1
Log.T_Direction := 1
Log.T_HasExited := 0
Log.T_ExCandle := 0
Log.T_ExPrice := 0
Log.T_TGTPrice := TGTType == "Point Based"
? math.round_to_mintick(Log.T_EnPrice + TGT_Value) : TGTType == "Capital" ?
math.round_to_mintick(Log.T_EnPrice + (TGT_Value / Log.T_Qty)) : na
Log.T_SLPrice := (SLType == "Point Based"
or SLType == "Point Based Trail") ? math.round_to_mintick(Log.T_EnPrice - SL_Value)
: SLType == "Capital DD" ? math.round_to_mintick(Log.T_EnPrice - (SL_Value /
Log.T_Qty)) : na
Log.NextTradeAfter := Log.T_EnCandle
Log.LongTrades += 1
Log.AllTrades += 1
Log.DaysTrades += 1
LongSetup.ToBreakValue := na
LongSetup.CrossCandle := na
LongSetup.MaxToTradeCandle := na
Log.Price2MoveForTrailing := if SLType == "Point
Based Trail" and (TGTType == "Point Based" or TGTType == "Capital")
math.round_to_mintick(Log.T_EnPrice + (math.abs(Log.T_TGTPrice -
Log.T_EnPrice) * TrailPCT))
else
na
Log.TrailSL_Val := if not
na(Log.Price2MoveForTrailing)
if LockSLAt == 0
Log.T_EnPrice
else if LockSLAt > 0
math.round_to_mintick(Log.T_EnPrice + (math.abs(Log.T_TGTPrice
- Log.T_EnPrice) * LockSLAt))
else
math.round_to_mintick(Log.T_SLPrice + (math.abs(Log.T_SLPrice -
Log.T_EnPrice) * math.abs(LockSLAt)))
Log.SL_Level := 0
else if ShortTadeEntry
Log.T_EnPrice := if barstate.isrealtime
and IsRealTime
close
else
ShortSetup.ToBreakValue
Log.T_Symbol := ScriptName
array.clear(MainLegSymbols)
for [index, value] in ListOfTradingAccount
Otype = value == "TRADINGVIEW" ?
"" : "L"
DirectionOfTrade = FutOrOps == "OPS" ? "BUY"
: "SELL"
[Symbol_T, AlertString_T] =
BEL.LegScriptContructor(FutOrOps == "OPS" ? true : false, IAO, deepness,
StrikeDiff,
true, "C", 0.0, 0.75, "NLB", FutOrOps == "OPS" ?
array.get(ListOfOptionsPrefix, index) : array.get(ListOfFuturePrefix, index), 0,
DirectionOfTrade, Log.T_QtyString, "", "", value, "MCX", Otype,
true, "0.1%")
array.push(MainLegSymbols, Symbol_T)
array.push(EntryAlertLegsArray, AlertString_T)
FinalEntryAlertText :=
BEL.LegConstructor(EntryAlertLegsArray, "NLB")
if str.length(FinalEntryAlertText) > 3
alert(FinalEntryAlertText, alert.freq_once_per_bar)
Log.T_En_Date_Time := DateTimeString
Log.T_EnCandle := bar_index
Log.T_Name := "Short | Cross Under
Trade on " + Log.T_Symbol
Log.T_HasEntered := 1
Log.T_Direction := -1
Log.T_HasExited := 0
Log.T_ExCandle := 0
Log.T_ExPrice := 0
Log.T_TGTPrice := TGTType == "Point Based"
? math.round_to_mintick(Log.T_EnPrice - TGT_Value) : TGTType == "Capital" ?
math.round_to_mintick(Log.T_EnPrice - (TGT_Value / Log.T_Qty)) : na
Log.T_SLPrice := (SLType == "Point Based"
or SLType == "Point Based Trail") ? math.round_to_mintick(Log.T_EnPrice +
SL_Value) : SLType == "Capital DD" ? math.round_to_mintick(Log.T_EnPrice +
(SL_Value / Log.T_Qty)) : na
Log.NextTradeAfter := Log.T_EnCandle
Log.ShortTrades += 1
Log.AllTrades += 1
Log.DaysTrades += 1
ShortSetup.ToBreakValue := na
ShortSetup.CrossCandle := na
ShortSetup.MaxToTradeCandle := na
Log.Price2MoveForTrailing := if SLType == "Point
Based Trail" and (TGTType == "Point Based" or TGTType == "Capital")
math.round_to_mintick(Log.T_EnPrice - (math.abs(Log.T_TGTPrice -
Log.T_EnPrice) * TrailPCT))
else
na
Log.TrailSL_Val := if not
na(Log.Price2MoveForTrailing)
if LockSLAt == 0
Log.T_EnPrice
else if LockSLAt > 0
math.round_to_mintick(Log.T_EnPrice - (math.abs(Log.T_TGTPrice
- Log.T_EnPrice) * LockSLAt))
else
math.round_to_mintick(Log.T_SLPrice - (math.abs(Log.T_SLPrice -
Log.T_EnPrice) * math.abs(LockSLAt)))
Log.SL_Level := 0
//#endregion
CloseCrossUnderTrend = ta.crossunder(close,
TrendLevel) and barstate.isconfirmed
CloseCrossOverTrend = ta.crossover(close,
TrendLevel) and barstate.isconfirmed
HasHitTGT = if Log.T_Direction == 1
and not na(Log.T_TGTPrice)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? high : close ,"GE", Log.T_TGTPrice)
else if Log.T_Direction == -1 and not na(Log.T_TGTPrice)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? low : close,"LE", Log.T_TGTPrice)
else
false
HasHitSL = if Log.T_Direction == 1
and not na(Log.T_SLPrice)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? low : close ,"L", Log.T_SLPrice)
else if Log.T_Direction == 1 and not na(ShortSetup.SLForTheTrade) and bar_index >
Log.ExitCandleCheck and (SLType == "Biased" or LookForBiasExit)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? low : close ,"L", ShortSetup.SLForTheTrade - 1)
else if Log.T_Direction == -1 and not na(Log.T_SLPrice)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? high : close,"G", Log.T_SLPrice)
else if Log.T_Direction == -1 and not na(LongSetup.SLForTheTrade) and bar_index >
Log.ExitCandleCheck and (SLType == "Biased" or LookForBiasExit)
BEL.OperatorChk(barstate.isrealtime and IsRealTime ? close :
barstate.isrealtime and not IsRealTime and barstate.isconfirmed ? close : not
barstate.isrealtime ? high : close,"G", LongSetup.SLForTheTrade + 1)
else
false
HasHitBias = if Log.T_Direction == 1
and CloseCrossUnderTrend and bar_index > Log.ExitCandleCheck and (SLType ==
"Biased" or LookForBiasExit)
true
else if Log.T_Direction == -1 and CloseCrossOverTrend and bar_index >
Log.ExitCandleCheck and (SLType == "Biased" or LookForBiasExit)
true
//#endregion
else if Log.T_Direction == -1
for [index, value] in ListOfTradingAccount
if FutOrOps == "OPS"
array.push(ExitAlertLegsArray, BEL.CancelClose(true, value,
"MCX", array.get(ListOfOptionsPrefix, index)))
else if FutOrOps == "FUT"
array.push(ExitAlertLegsArray, BEL.CancelClose(false, value,
"MCX", array.get(ListOfFuturePrefix, index), "A", "S"))
FinalExitAlertMessage :=
BEL.LegConstructor(ExitAlertLegsArray, "NLB")
if str.length(FinalExitAlertMessage) > 3
alert(FinalExitAlertMessage, alert.freq_once_per_bar)
Log.T_Ex_Date_Time := DateTimeString
Log.T_ExCandle := bar_index
Log.T_ExPrice := if barstate.isrealtime
close
else if not na(LongSetup.SLForTheTrade) and SLType == "Biased"
LongSetup.SLForTheTrade
else if high > Log.T_SLPrice and SLType != "Biased"
Log.T_SLPrice
else if HasHitTGT
Log.T_TGTPrice
else
close
Log.NextTradeAfter := Log.T_ExCandle
Log.T_HasExited := 1
Log.T_HasEntered := 0
Log.T_Direction := 0
PNLCalc = (Log.T_EnPrice - Log.T_ExPrice) *
TradeQty
array.push(Days_PNL, PNLCalc)
array.push(OverAll_PNL, PNLCalc)
array.push(LogSummary, Log.T_En_Date_Time + " | " +
str.tostring(Log.T_EnPrice, format.mintick) + " || " + Log.T_Ex_Date_Time + " | " +
str.tostring(Log.T_ExPrice, format.mintick) + " || PNL : " +
str.tostring(PNLCalc,format.mintick))
Last_TradePNL := PNLCalc
if PNLCalc > 0
Log.ProfitableTrade += 1
if not na(LongSetup.SLForTheTrade)
LongSetup.SLForTheTrade := na
float yLow = low
for x = 0 to (bar_index - Log.T_EnCandle)
yLow := math.min(yLow, low[x])
Log.MaxTradeROI := Log.T_EnPrice - yLow
array.push(MaxTradeROI_Array, math.round_to_mintick(Log.MaxTradeROI))
else
ExitAlertString = array.new_string(0)
if Log.T_HasExited == 0 and Log.T_HasEntered == 1 and Log.T_Direction != 0
for [index, value] in ListOfTradingAccount
array.push(ExitAlertString, BEL.CancelClose(true, value, "MCX",
array.get(ListOfOptionsPrefix, index)))
array.push(ExitAlertString, BEL.CancelClose(true, value, "MCX",
array.get(ListOfFuturePrefix, index)))
AlertMessage =
BEL.LegConstructor(ExitAlertString, "NLB")
alert(AlertMessage, alert.freq_once_per_bar)
Log.T_Ex_Date_Time := DateTimeString
Log.T_ExCandle := bar_index
Log.T_ExPrice := barstate.isrealtime ? close :
ohlc4
Log.NextTradeAfter := bar_index + 100
PNLCalc = if Log.T_Direction == 1
(Log.T_ExPrice - Log.T_EnPrice) * TradeQty
else if Log.T_Direction == -1
(Log.T_EnPrice - Log.T_ExPrice) * TradeQty
float y = Log.T_Direction == 1 ? high : low
for x = 0 to (bar_index - Log.T_EnCandle)
if Log.T_Direction == -1
y := math.min(y, low[x])
else
y := math.max(y, high[x])
Log.MaxTradeROI := Log.T_Direction == -1 ?
Log.T_EnPrice - y : y - Log.T_EnPrice
array.push(MaxTradeROI_Array, math.round_to_mintick(Log.MaxTradeROI))
Log.T_Direction := 0
array.push(Days_PNL, PNLCalc)
array.push(OverAll_PNL, PNLCalc)
array.push(LogSummary, Log.T_En_Date_Time + " | " +
str.tostring(Log.T_EnPrice, format.mintick) + " || " + Log.T_Ex_Date_Time + " | " +
str.tostring(Log.T_ExPrice, format.mintick) + " || PNL : " +
str.tostring(PNLCalc,format.mintick))
Last_TradePNL := PNLCalc
if PNLCalc > 0
Log.ProfitableTrade += 1
LongSetup.SLForTheTrade := na
ShortSetup.SLForTheTrade := na
Log.T_HasExited := 1
Log.T_HasEntered := 0
//#endregion