This is my first post. I have written one explorer for Call Ratio Spread. On one Minute TF, it is producing 93375 records instead of 375 records. It is repeating 249 times same values for example 9:15am candle.
Here is the code.
/*
Strategy for CAll Ratio Profits and Loss
TimeFrame = 1min
This is explorer. It will not plot any thing
*/
function OptionStrike ( Spot, div)
{
local spot, div;
frp = Spot % div;
atm = Spot - frp + (frp !=0)*div;
return atm;
}
_N( Symbol3= ParamStr("Spot", "NIFTY") );
_N( Symbol4= ParamStr("Future", "NIFTY-1") );
_N( Symbol0= Paramlist("Option Symbol", "NIFTY|NIFTYWK|BANKNFITY|BANKNFITYWK" , 1) );
s1_Lot1= Param("s1 - CeRatio - Lots for Short Strike1", 20, 1, 10000, 1); //Upper Strike
s1_Lot2= Param("s1 - CeRatio - Lots for Long Strike2", 10, 1, 10000, 1); // Lower Strike
s1_strike1= Param("s1-CERatio SELL Strike:", 11650, 50, 50000, 50);
s1_strike2= Param("s1-CERatio BUY Strike:", 11600, 50, 50000, 50);
EntryTime= ParamTime("Entrytime:", "10:30:00", 0);
Margin1= Param("Enter Margin% (12):" , 12, 1, 100, 0.01);
Leverage= Param("Enter the Leverage (10X):", 10, 1, 100, 1, 1);
if ( StrLeft( Symbol0, 5) == "NIFTY") lotsize=50;
if ( StrLeft( Symbol0, 9) == "BANKNIFTY") lotsize=100;
// Spot Data
SetForeign( symbol3, 1, 0 );
C3 = C; H3 = H;
L3 = L; O3 = O;
V3 = V; avg3 = Avg; OI3 = OI;
dc3 = ROC(C, 1);
doi3 = ROC(OI, 1);
dv3= ROC(V, 1);
spot= C3;
TimeFrameSet(inDaily);
spotATR= ATR(14);
TimeFrameRestore();
spotATR= TimeFrameExpand(SpotATR, inDaily, expandFirst);
RestorePriceArrays();
// Future Data
SetForeign( symbol4, 1, 0 );
fut=C4 = C; H4 = H;
L4 = L; O4 = O;
V4 = V; avg4 = Avg; OI4 = OI;
dc4 = ROC(C, 1);
doi4 = ROC(OI, 1);
dv= ROC(V, 1);
TimeFrameSet(inDaily);
FutATR= ATR(14);
TimeFrameRestore();
FutATR= TimeFrameExpand(FutATR, inDaily, expandFirst);
RestorePriceArrays();
spotATM= OPtionStrike(spot, lotsize);
futATM= OPtionStrike(fut, lotsize);
tn= TimeNum();
// Get Foreign Prices:
s1_Symbol1= Symbol0 + NumToStr(s1_strike1, 1.0, False) + "CE";
SetForeign( s1_Symbol1, 1, 0 );
s1_p1ce = Close;
RestorePriceArrays();
s1_Symbol2= Symbol0 + NumToStr(s1_strike2, 1.0, False) + "CE";
SetForeign( s1_Symbol2, 1, 0 );
s1_p2ce = Close;
RestorePriceArrays();
// Strategy1: Call Ratio Spread
s1_e1= SelectedValue( ValueWhen(tn == entrytime, s1_p1ce, 1) );
s1_e2= SelectedValue( ValueWhen(tn == entrytime, s1_p2ce, 1) );
// in points
s1_pnl1= s1_Lot1 * ( s1_E1 - s1_p1ce ); //short points
s1_pnl2= s1_Lot2 * ( s1_p2ce - s1_E2 ); //long points
s1_PnlT= s1_pnl1 + s1_Pnl2; //Pnl Points
// Pnl in INR ===========================
s1_T_Pnl1 = lotsize* s1_pnl1;
s1_T_Pnl2 = lotsize* s1_pnl2;
s1_NetPnl= s1_T_pnl1 + s1_T_Pnl2;
Filter = 1;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
// Common =========
AddColumn( C3, "spot", 1.2 );
AddColumn( c4, "fut", 1.2 );
AddColumn( c4-c3, "Prem" , 1.2 );
AddColumn( spotATM, "ATM" , 1.2 );
// Entry Prices
AddColumn( s1_E1, "SEN-CE1", 1.2 );
AddColumn( s1_E2, "BEN-CE2", 1.2 );
// Last Traded Price of strikes
AddColumn( s1_p1ce, "SCE1-" + StrRight( s1_symbol1, 7), 1.2 );
AddColumn( s1_p2ce, "BCE2-" + StrRight( s1_symbol2, 7), 1.2 );
// Pnl of each leg and total pnl
AddColumn( s1_T_Pnl1, "PNL$CE1", 1.2, colorDefault, IIf(s1_T_Pnl1 > 0, colorBrightGreen, colorRose) );
AddColumn( s1_T_Pnl2, "PNL$CE2", 1.2, colorDefault, IIf(s1_T_Pnl2 > 0, colorBrightGreen, colorRose) );
AddColumn( s1_NetPnl, "PNL$SPD", 1.2, colorDefault, IIf(s1_NetPnl > 0, colorBrightGreen, colorRose) );
Can you please let me know what I have done incorrectly? Any guidance will help me improve this explorer.