I added option chain in the watchlist. I want to trade one of the options on predefined conditions. I am not able to get the result (buy the put/call option) in either exploration/backtesting. Please guide me.
Have you checked if the actual output of this string matches such a symbol in DB? Call = "NIFTY18DEC" + (round(C /100)+ 5 )*100 + "CE";
AddTextColumn(Symbol, "Symbol");
Instead of using this line multiple times in code blocks, you should use a variable that stores the string, and call this line once at the end of the code along with other Column definitions.
It will work and probably add columns but what about the various rows that may generate, anyway, its your partial code but I feel its not a good coding practice.
Yes Call = "NIFTY18DEC" + (round(C /100)+ 5 )*100 + "CE" is the actual match with DB.
AddtextColumn is just added to check result whether the code fetches correct symbol or not.
I am newbie. I will gain proficiency simultaneously as learning is never ending process. But I am stuck with this part. I had gone through various KBs but not able to get how to go forward.
Problem Is not with AB, but what you are doing will not happen that way as of now. There are logical reasons for it.
You have to design your code in the way described if you want to Backtest it.
If you are trading live and just want to fire a signal for example, then you can call your Brokers API from that IF() and fire a trade right away but these are two very different things.
There are more code examples in the Forum, but you need to write a CBT (Mid-level atleast) and that is fairly advanced.
One more thing, Suppose in multi-stock trading if we purchase one stock out of 5 stocks on t day.
How to code if we want to sell that particular stock on very next day ie t+1 as soon as market open.
Q2 is fine, you can AND it with the Buy signal code.
Q1. This will create problems because now you are in intraday timeframe and you are not back testing either.
1 day and 1 bar in intra TF are two very different things.
Also, hold min N bars will not make much sense in an intra TF because there are very many bars.
Because you have changed your strategy and therefore your code, I don't have a specific context but its better to go with a more generalized approach.
If barsSinceBuy > barsSinceToday, you know its a previous day (or more). You will have finer control as you need and any intra TF wont matter or need adjustment instead of hardcoding number of bars.