Tradingview Pinescript strategy.close() strategy.exit() coemment problem - bots

I'm taring to adjust the strategy on Tradingview to work together with bot using alerts (tradingview).
My problem is that comments have to be the same in strategy.close and strategy.exit
There is any possibility that script will automatically when the condition will be fulfilled for strategy.close to take the comment from strategy.exit ?
Many thanks for help and all the best for You!
/ === STRATEGY - LONG POSITION EXECUTION ===
strategy.entry(id = "Buy", long = true, when = buy[shunt]==1, comment = "ENTER-LONG_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c621" )
strategy.close(id = "Buy", when = direction[shunt]!=direction[shunt+1], comment = "EXIT-LONG_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c21")
// === STRATEGY - SHORT POSITION EXECUTION ===
strategy.entry(id = "Sell", long = false, when = sell[shunt]==1, comment = "ENTER-SHORT_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c621")
strategy.close(id = "Sell", when = direction[shunt]!=direction[shunt+1], comment = "EXIT-SHORT_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c621")
// === STRATEGY RISK MANAGEMENT EXECUTION ===
strategy.exit("Exit Buy", from_entry = "Buy", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset, comment = "EXIT-LONG_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c6c021")
strategy.exit("Exit Sell", from_entry = "Sell", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset, comment = "EXIT-SHORT_BINANCE-FUTURES_ETHBUSD_ETH_30M_9c6c021")
Error
9:23:54 AM — Compilation error. Line 194: Cannot call `strategy.close` with arguments (literal__string, fun_call__operator !=, literal__string); available overloads: strategy.close(literal__string, series__bool) => void;
line 198: Cannot call `strategy.close` with arguments (literal__string, fun_call__operator !=, literal__string); available overloads: strategy.close(literal__string, series__bool) => void
There is any possibility that script will automatically when the condition will be fulfilled for strategy.close to take the comment from strategy.exit ?
Many thanks for help and all the best for You!

Your problem doesn't come from the comments.
You can use the same comments, no problem.
Your error comes from :
when = direction[shunt]!=direction[shunt+1]
in your strategy.close order.
Please update to pinescript v5 and do not use 'when' in your strategy.close, but put your strategy.close in an 'if' block.

Related

What is the problem in the following code?

I want to generate auto generate book fine of 10% of book cost. I have written the following code but nothing happens. No error comes and not working. book_cost field is in book module.
Please check code.
issue_date = fields.Date('Issue Date', required=True, tracking=True)
due_date = fields.Date('Due Date', required=True, tracking=True)
book_ids = fields.Many2many('odooschool.library.books','tch_book_rel','book_name','teacher_id','Issued Books')
sequence = fields.Integer('sequence')
fine_amount = fields.Char('Fine Amount', compute='_get_cost_details')
submission_date = fields.Date.today()
price = fields.Char('Price')
#api.depends('due_date','book_ids.book_cost')
def _get_cost_details(self):
market_multiplier = 0
date_return = fields.Date()
for rec in self:
fine_amount = 0
if rec.due_date and rec.submission_date and rec.due_date > rec.submission_date:
date_return = (rec.due_date - rec.submission_date)
market_multiplier = int(decimal.Decimal('0.10'))
fine_amount = rec.book_ids.book_cost * market_multiplier
rec.fine_amount += rec.fine_amount
I think if you replace
submission_date = fields.Date.today()
by
submission_date = fields.Date(default= fields.Date.today)
That will be work. Cause the submission_date in your code is always the starting date of Odoo server.
Regards

How to set guild_subscriptions event to true in discord.py?

I am facing a problem in discord.py, the following code is running perfectly, but ctx.guild.owner returns none, and in documentation it says that if this happens the event guild_subscriptions is set to False, how can I set this event to True in order to make it work? I can't find any solution in discord.py documentation, neither Google.
The code of my serverstats command:
#commands.command(name="serverstats", aliases = ["serverinfo", "si", "ss", "check-stats", 'cs'])
async def serverstats(self, ctx: commands.Context):
embed = discord.Embed(
color = discord.Colour.orange(),
title = f"{ctx.guild.name}")
embed.set_thumbnail(url = f"{ctx.guild.icon_url}")
embed.add_field(name = "ID", value = f"{ctx.guild.id}")
embed.add_field(name = "👑Owner", value = f"{ctx.guild.owner}")
embed.add_field(name = "🌍Region", value = f"{ctx.guild.region}")
embed.add_field(name = "👥Member Count", value = f"{ctx.guild.member_count}")
embed.add_field(name = "📆Created at", value = f"{ctx.guild.created_at}")
embed.set_footer(icon_url = f"{ctx.author.avatar_url}", text = f"Requested by {ctx.author.name}")
await ctx.send(embed=embed)
the event guild_subscriptions is set to False
I can't find any solution in discord.py documentation
It's not an event. The docs say it's a parameter when creating a commands.Bot instance, and that you can find in the documentation for Clients, which you can. If you scroll down to the bottom of that list of parameters, you'll see guild_subscriptions(bool), which is what you're looking for.
To enable this, all you have to do is add it to the code where you create your Client:
client = commands.Bot(command_prefix=your_prefix, guild_subscriptions=True)
Also, since Discord 1.5 you now need to pass the correct Intents, and the documentation for Client states that you need to have Intents.members enabled if you don't want guild.owner to return None, which is also what's causing your issue. You also have to pass these intents as a parameter, so the final thing would end up looking something like this:
# Configure intents (1.5.0)
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix=your_prefix, guild_subscriptions=True, intents=intents)

PRAW for loop only returning last value

Trying to create a PRAW scraper that can pull the comments from a list of sub_ids. Only returns the last sub_ids comment data.
I'm guessing I must be overwriting something. I've looked through other questions but because I'm using PRAW it has specific parameters and I can't figure out what could/should be replaced.
sub_ids = ["2ypash", "7ocvlb", "7okxkf"]
for sub_id in sub_ids:
submission = reddit.submission(id=sub_id)
submission.comments.replace_more(limit=None, threshold=0)
comments = submission.comments.list()
commentlist = []
for comment in comments:
commentsdata = {}
commentsdata["id"] = comment.id
commentsdata["subreddit"] = str(submission.subreddit)
commentsdata["thread"] = str(submission.title)
commentsdata["author"] = str(comment.author)
commentsdata["body"] = str(comment.body)
commentsdata["score"] = comment.score
commentsdata["created_utc"] = datetime.datetime.fromtimestamp(comment.created_utc)
commentsdata["parent_id"] = comment.parent_id
commentlist.append(commentsdata)
Indentation was your downfall. The reason your code was failing was because comments were only assigned after the sub_ids have finished looping. So when you iterate through comments, they're only the last sub_id's comments.
First, move the commentlist = [] out before both for loops (so that it's right after line 1)
Second, everything from comments = submission.comments.list() (inclusive) onward needs to be indented so they're ran within the sub_ids iteration.
Here is what it should look like finally:
sub_ids = ["2ypash", "7ocvlb", "7okxkf"]
commentlist = []
for sub_id in sub_ids:
submission = reddit.submission(id=sub_id)
submission.comments.replace_more(limit=None, threshold=0)
comments = submission.comments.list()
for comment in comments:
commentsdata = {}
commentsdata["id"] = comment.id
commentsdata["subreddit"] = str(submission.subreddit)
commentsdata["thread"] = str(submission.title)
commentsdata["author"] = str(comment.author)
commentsdata["body"] = str(comment.body)
commentsdata["score"] = comment.score
commentsdata["created_utc"] = datetime.datetime.fromtimestamp(comment.created_utc)
commentsdata["parent_id"] = comment.parent_id
commentlist.append(commentsdata)

Odd behaviour of insertNewObjectForEntityForName leading to NSInternalInconsistencyException

I have a rather odd case of getting a core data error whilst experimenting with Swift. I am not sure whether it comes from Swift (beta error?) or whether it is me. However, here is the setup for my test cases (in VTModelTests.swift).
var bundle = NSBundle(forClass: VTModelTests.self)
var url = bundle.URLForResource("VTDocument", withExtension:"momd")
appleModel = NSManagedObjectModel(contentsOfURL: url)
assert (appleModel != nil)
var coord = NSPersistentStoreCoordinator(managedObjectModel: appleModel);
var store = coord.addPersistentStoreWithType(NSInMemoryStoreType,configuration:nil,URL:nil,options:nil,error:nil);
assert (store != nil)
ctx = NSManagedObjectContext();
ctx!.persistentStoreCoordinator=coord
ctx!.retainsRegisteredObjects=true;
var drwName = "Drawing"
var descs = ctx!.persistentStoreCoordinator.managedObjectModel.entitiesByName
for e : AnyObject in descs.allKeys{
assert (descs.objectForKey(e).name == e as String )
if (e as String == drwName) {
NSLog("yeah")
}
}
model = NSEntityDescription.insertNewObjectForEntityForName(drwName,inManagedObjectContext: ctx) as Drawing
My error message looks like this:
2014-06-22 22:12:25.584 xctest[63792:303] yeah
<unknown>:0: error: -[_TtC12VTModelTests12BaseTypeTest testTreeStructure] : failed: caught "NSInternalInconsistencyException", "+entityForName: could not locate an entity named 'Drawing' in this model."
In short, I can "prove" that the entity name is there (the 'yeah' in the log), but core data is showing the issue that the name would not be in the model. Previous versions of the loop printed out the entities and that looked good. I don't have any second versions, and a new changed name ('Model' is now called 'Drawing') is correctly shown in the model data when all entities are printed. The compiled model is in the resulting bundle.
Can anybody explain? Or do I have to wait for the next beta release of Xcode 6? What else did I overlook? Many thanks in advance!
I can confirm the issue. Not an answer but the way around I use is to split insertNewObjectForEntityForName into:
let entity = NSEntityDescription.entityForName("Photo", inManagedObjectContext:context)
let photo = Photo(entity:entity, insertIntoManagedObjectContext:context)

How to get rid of lmer warning message?

I have made some changes to the lmer. It works as it should but I could not get rid of the warning message that pops when I run the program. I have added the following options which allows the program run without stopping but with the warning message. I believe it is the check.nobs.vs.rankZ = "warningSmall" part. How could I get rid of this, any suggestions? Thank you.
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"warningSmall",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),check.scaleX = "ignore",check.formula.LHS="ignore",
## convergence checking options
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL),
check.conv.singular = .makeCC(action = "ignore", tol = 1e-4),
check.conv.hess = .makeCC(action = "warning", tol = 1e-6)
Warning Message from R:
Warning message:
In checkZrank(reTrms$Zt, n = n, control, nonSmall = 1e+06) :
number of observations (=300) <= rank(Z) (=300); the random-effects parameters and the
residual variance (or scale parameter) are probably unidentifiable
You should try check.nobs.vs.rankZ="ignore".
lmerControl doesn't need to specify anything other than the non-default options: at a quick glance, these are your non-default values:
lmerControl(check.nobs.vs.nlev = "ignore",check.nobs.vs.rankZ =
"ignore",check.nlev.gtreq.5 = "ignore",check.nobs.vs.nRE="ignore",
check.rankX = c("ignore"),
check.scaleX = "ignore",
check.formula.LHS="ignore",
check.conv.grad = .makeCC("warning", tol = 1e-3, relTol = NULL))
In general I would suggest it's wise to turn off only the specific warnings and errors you know you want to override -- the settings above look like they could get you in trouble.
I haven't checked this since you didn't give a reproducible example ...

Resources