I'm a newbie for TradingView and have been learning a lot. I'm developing a strategy with backtesting using pine-script language however what confusing me, is how to use the same strategy for multiple coins.
The strategy is mainly developed for Binance Futures trading not sure if possible to apply it to other Exchangers.
So I wanna setup alerting system for multiple coins to be connected to 3comma Bot or Finandy to execute a trade based on the setup parameter.
My questions are.
If I wanna use certain candle types like Hiken Ashi should that be included in the code or just select it in the chart and it will be read by the strategy automatically?
Should I include the coins in the script or I should select them one by one in the chart and then setup an alert per coin?
Should I create one alert per one coin per chart or I should have multiple charts per each coin to setup an alert?
Should the timeframe also be defined in the code or the chart can do the job?
Sorry for many questions, I'm trying to understand the process well.
For multiple coins, the easiest way is to attach your strategy to each and every coin on Tradingview you want to trade with. This way you can backtest each on their respective chart.
If you create a strategy for say BINANCE:BTCUSDT and think of using this strategy on different exchange, you can do it, but first I suggest test it on BINANCE:BTCPERP and see for yourself how the same strategy can show a wildly different result (even though BTCUSDT and BTCPERP should be moving the same).
For a complex solution you can create a single script that uses multiple securities, but you won't be able to backtest that with simple approach, you would have to write your own gain/loss calculator, and you are not there yet.
I was going down the same road, my suggestions are:
create an input for the coin you want to trade (that will go into an input variable)
abstract the alert message off of the strategy.entry() command, that is, construct the alert message in a way you can replace values with variables in it (like the above selected coin)
3Commas needs a Bot ID to start/stop a bot, abstract that off as well, and you will have a good boilerplate code you can reuse many times
as a good practice (stolen from Kubernetes) besides the human readable name, I give a 5 letter identifier to every one of my bots, for easy recognition
A few examples. The below will create a selector for a coin and the Bot ID that is used to trade that coin. The names like 'BIN:GMTPERP - osakr' are entirely my making, they act as a Key (for a key/value pair):
symbol_choser = input.string(title='Ticker symbol', defval='BTC-PERP - aktqw', options=[FTX_Multi, 'FTX:MOVE Single - pdikr', 'BIN:GMTPERP - osakr', 'BIN:GMTPERP - rkwif', 'BTC-PERP - aktqw', 'BTC-PERP - ikrtl', 'BTC-PERP - cbdwe', 'BTC-PERP', 'BAL-PERP', 'RUNE-PERP', 'Paper Multi - fjeur', 'Paper Single - ruafh'], group = 'Bot settings')
exchange_symbol = switch symbol_choser // if you use Single Pair bots on 3Commas, the Value should be an empty string
'BIN:GMTPERP - osakr' => 'USDT_GMTUSDT'
'BTC-PERP - cbdwe' => 'USD_BTC-PERP'
'Paper Multi - fjeur' => 'USDT_ADADOWN'
bot_id = switch symbol_choser
'BIN:GMTPERP - osakr' => '8941983'
'BTC-PERP - cbdwe' => '8669136'
'Paper Multi - fjeur' => '8246237'
And now you can combine the above parts into two Alerts, for starting/stopping the bot:
alertMessage_Enter = '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
alertMessage_Exit = '{"action": "close_at_market_price", "message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
exchange_symbol is the proper exchange symbol you need to provide to your bot, you can get help on the 3Commas' bot page (they have pre-crafted the HTTP requests you need to use for certain actions).
bot_id is the ID of your Bot, that is straightforward.
The above solution does not handle Single coin bots, their trigger message has a different structure.
Whenever you can, use Multi coin bots as they can act as a Single bot with two exception:
if you have a long spanning strategy and when you start a bot, you should be already in a trade, you can manually start a Single bot, but you cannot start a Multi coin bot (as there is no way to provide the coin info on which to start the trade)
if you are trading a derivative like FTX's MOVE contracts and your script is attached to the underlying BTC Futures. MOVE contracts changes name every day (the date is in their name, like: BTC-MOVE-0523) so you would need delete an alert, update and reapply the alert every day, etc. Instead, if your script is on the BTC-PERP then you can use a Single coin bot which does not expect a coin name in the alert message so it will start/stop the Bot on whatever coin it is connected to, then you need to change the coin name every day only in the Bot settings and never touch the Alert.
To summarize on your questions:
Do not include chart type in code (that is not even an embeddable data), just apply your code to whatever chart you want to use. Hint: never use Heikin-Ashi for trading. You can, but you will pay for it dearly (everyone tries, even against warnings, no worries)
Set up them one-by-one, so you can backtest them
No, set the timeframe on the chart. Later, when you will be more experienced you will be able to abstract the current timeframe (whatever it is) away and write code that is timeframe-agnostic. But that's hard and make your code less readable.
Related
TL:DR
I want to lable results in the backend.
I have a flask/celery project and I'm new to celery.
A user sends in a batch of tasks for celery to work on.
Celery saves the results to a backend SQL database (table automatically created by Celery, named celery_taskmeta).
I want to let the user see the status of his batch, and request the results from the backend.
My problem is that all the results are in one table. What are my options to lable this batch, so the user can differentiate the batches?
My ideas:
Can I add a lable to each task, e.g. "Bob's batch no. 12" and then query celery_taskmeta for that?
Can I put each batch in named backend tables, so ask Celery to save results to a table named task_12?
Trying with groups
I've tried the following code to group the results
job_group = group(api_get.delay(url) for url in urllist)
But I don't see any way to identify the group in the backend/results DB
Trying with task name
In the backend I see an empty column header 'name' so I thought I could add an arbitrary string there:
#app.task(name="an amazing vegetable")
def api_get(url: str) -> tuple:
...
But then the celery worker throws an error when I run the task:
KeyError: 'an amazing vegetable'
[2020-12-18 12:07:22,713: ERROR/MainProcess] Received unregistered task of type 'an amazing vegetable'.
Probably the simplest solution is to use Group and use the Group Result to periodically poll for group state.
A1: As for the label question - yes, you can "label" your task by using the custom state feature.
A2: you can hack around to put each batch of tasks inside backend table, but I strongly advise not to mess with it. If you really want to go this route, make a separate database for this particular use.
Let me stress that I am not a programmer but I like messing around with things. I've been using #ifttt and #nest for years and recently started using #smartthings to do cool things in my house.
I wanted to power off devices such as my lights and water heater based on leaving my house. Rather than having this depend on one device such as a phone or keyfoob, I wanted to use the nest "auto-away" feature.
Auto-away doesn't appear to be exposed to #ifttt or #smartthings. I've asked #nestsupport and they told me to come here :-o.
Does anyone from nest developer team know when developers and other products will be able to consume this from he nest device? Its a real shame that after several years this isn't exposed yet. Not only that but it could be an additional selling point to integrate and turn on/off items in your house.
Thank
I'm not from the Nest developer team, but I've played around with the Nest API in the past, and use it to plot my energy usage.
The 'auto away' information is already accessible in the API, and looks to be used in a number of IFTTT recipes:
https://ifttt.com/recipes/search?q=auto+away&ac=false
Within the (JSON) data received back in the API, the 'auto away' status is accessible via;
shared->{serial_number}->auto_away
This is set as a boolean (0 or 1).
If you like messing around with code, and know any PHP, then this PHP class for the Nest API is very useful at grabbing all information etc;
https://github.com/gboudreau/nest-api
Auto-Away is and always has been readable https://developer.nest.com/documentation/cloud/api-overview#away
There are a few ways you could go about doing this, but if you're writing up a SmartApp just for your own uses, I'd suggest piggybacking off of one of the existing device types for the Nest on SmartThings. As a quick example, I'll use the one that I use:
https://github.com/bmmiller/device-type.nest/blob/master/nest.devicetype.groovy
After line 96, this is to expose the status to any SmartApp you may write:
attribute "temperatureUnit", "string"
attribute "humiditySetpoint", "number"
attribute "autoAwayStatus", "number" // New Line
Now, you'll want to take care of getting the data in the existing poll() method, currently starting at line 459.
After line 480, to update the attribute
sendEvent(name: 'humidity', value: humidity)
sendEvent(name: 'humiditySetpoint', value: humiditySetpoint, unit: Humidity)
sendEvent(name: 'thermostatFanMode', value: fanMode)
sendEvent(name: 'thermostatMode', value: temperatureType)
sendEvent(name: 'autoAwayStatus', value: data.shared.auto_away) // New Line
This will expose a numerical value for the auto_away status.
-1 = Auto Away Not Enabled
0 = Auto Away Off
1 = Auto Away On
Then, in your SmartApp you write, where you include an input of type thermostat like this:
section("Choose thermostat... ") {
input "thermostat", "capability.thermostat"
}
You will be able to access the Auto Away status by referring to
thermostat.autoAwayStatus
From anywhere in your code where you can do something like
if (thermostat.autoAwayStatus == 1) {
// Turn off everything
}
I have a cakephp 1.3 application and I have run into a 'data leak' security hole. I am looking for the best solution using cake and not just something that will work. The application is a grade tracking system that lets teachers enter grades and students can retrieve their grades. Everything is working as expected but when I started to audit security I found that the basic CRUD operations have leaks. Meaning that student X can see student Y's grades. Students should only see their own grades. I will limit this questions to the read operation.
Using cake, I have a grade_controller.php file with this view function:
function view($id = null) {
// Extra, not related code removed
$this->set('grade', $this->grade->read(null, $id));
}
And
http://localhost/grade/view/5
Shows the grade for student $id=5. That's great. But if student #5 manipulates the URL and changes it to a 6, person #6's grades are shown. The classic data leak security hole.
I had two thoughts on the best way to resolve this. 1) I can add checks to every CRUD operations called in the controller. Or 2) add code to the model (for example using beforeFind()) to check if person X has access to that data element.
Option #1 seems like it is time consuming and error prone.
Option #2 seem like the best way to go. But, it required calling find() before some operations. The read() example above never executes beforeFind() and there is no beforeRead() callback.
Suggestions?
Instead of having a generic read() in your controller, you should move ALL finds, queries..etc into the respective model.
Then, go through each model and add any type of security checks you need on any finds that need to be restricted. 1) it will be much more DRY coding, and 2) you'll better be able to manage security risks like this since you know where all your queries are held.
For your example, I would create a getGrade($id) method in my Grade model and check the student_id field (or whatever) against your Auth user id CakeSession::read("Auth.User.id");
You could also build some generic method(s) similar to is_owner() to re-use the same logic throughout multiple methods.
If CakePHP supports isAuthorized, here's something you could do:
Create a column, that has the types of users (eg. 'student', 'teacher', ...)
Now, it the type of User is 'student', you can limit their access, to view only their data. An example of isAuthorized is as follows. I am allowing the student to edit only their profile information. You can extend the concept.
if ((($role['User']['role'] & $this->user_type['student']) == $this->user_type['student']) {
if (in_array($this->action, array('view')) == true) {
$id = $this->params->pass[0];
if ($id == $user_id) {
return (true);
}
}
}
}
Have been working on a two-player turn based game that uses a custom UI for match management. Considering restricting the app to iOS 6+ in order to use player timeouts. I would like to show the user the remaining amount of time to move, but the participant.timeoutDate is always null? Per the WWDC 2012 video (that says the timeout won't apply to the last participant in nextParticipants), I pass an array with two entries (opponent at index 0 and local player at index 1) when calling endTurnWithNextParticipants:turnTimeout:matchData:completionHandler: to take a turn. I've tried both GKTurnTimeoutDefault and various integer literals ... no luck ... always seems to be null. The player's last turn date works fine.
On the subject of player timeouts ... after I get them working, how is this delivered? I see GKTurnBasedMatchOutcomeTimeExpired ... does this come in a turn event?
From Apple's developer forum
Elian Gidoni -
+1
The doc should be:
timeoutDate
The date and time when the participant’s turn timed out. (read-only)
Does anybody know how to limit a users ability to set variables? Specifically statement_timeout?
Regardless of if I alter the user to have this variable set to a minute, or if I have it set to a minute in the postgresql.conf file, a user can always just type SET statement_timeount TO 0; to disable the timeout completely for that session.
Does anybody know a way to stop this? I know some variables can only be changed by a superuser but I cannot figure out if there is a way to force this to be one of those controlled variables. Alternatively, is there a way to revoke SET from their role?
In my application, this variable is used to limit the ability of random users (user registration is open to the public) from using up all the CPU time with (near) infinite queries. If they can disable it then it means that I must find a new methodology for limiting resources to users. If there is no method for securing this variable, is there other ways of achieving this same goal that you may suggest?
Edit 2011-03-02
The reason the database is open to the public and arbitrary SQL is allowed is because this project is for a game played directly in the database. Every player is a database user. Data is locked down behind views, rules and triggers, CREATE is revoked from public and the player role to prevent most alterations to the schema and SELECT on pg_proc is removed to secure game-sensitive function code.
This is not some mission critical system I have opened up to the world. It is a weird proof of concept that puts an abnormal amount of trust in the database in an attempt to maintain the entire CIA security triangle within it.
Thanks for your help,
Abstrct
There is no way to override this. If you allow the user to run arbitrary SQL commands, changing the statement_timeout is just the top of the iceberg anyway... If you don't trust your users, you shouldn't let them run arbitrary SQL - or accept that they can run, well, arbitrary SQL. And have some sort of external monitor that cancels the queries.
Basically you can't do this in plain postgres.
Meantime for accomplish your goal you may use some type of proxies and rewrite/forbidd some queries.
There several solutions for that, f.e.:
db-query-proxy - article how it born (in Russian).
BGBouncer + pgbouncer-rr-patch
Last contains very useful examples and it is very simple do on Python:
import re
def rewrite_query(username, query):
q1="SELECT storename, SUM\(total\) FROM sales JOIN store USING \(storeid\) GROUP BY storename ORDER BY storename"
q2="SELECT prodname, SUM\(total\) FROM sales JOIN product USING \(productid\) GROUP BY prodname ORDER BY prodname"
if re.match(q1, query):
new_query = "SELECT storename, SUM(total) FROM store_sales GROUP BY storename ORDER BY storename;"
elif re.match(q2, query):
new_query = "SELECT prodname, SUM(total) FROM product_sales GROUP BY prodname ORDER BY prodname;"
else:
new_query = query
return new_query