write the entry code for the purchase and sale transaction in Pine Script - pine-script-v5

is there a code that can be used for example in the time frame of 15 minutes
Close the first positive candle
After the closing of the second candle, if it closes green, give a signal to enter the long trade

Related

PineScript Variables Intermittent Vales during candle making

I have a question regarding variables value during pine script execution.
Below picture shows a scenario on a five minute chart. In the first candle 11.00 am, the close price is 9200. New candle starts at 11.05 am and this candle is in making. Initially the price is 9100 and then changes to 8900, 9150, 9500 and 9300.
Inside the pinescript script there is a boolean "var lessthan9K" which stores the latest value. This variable is set to true if value goes less than 9000. This value remains true till other condition is met - Greater than 10000. It becomes false when value goes above 10000.
When new candle is in making and when price goes to 8900 at 11.06 am, lessthan9k variable becomes true. My question is whether this value remains true end of the candle when final close price is 9300 # 11.09 am or it resets to false?
Basically how does it work ? During the candle making, any intermittent values are stored or lost (from 1 to 5)?
Thanks
What you call intermittent values are lost because of the rollback process in the realtime bar. See the usrman's Calculation based on realtime bars section for an explanation.

AnyLogic mean waiting time in queue

I would like to get the mean waiting time of each unit spending in my queue of every hour. (so betweeen 7-8 am for example 4 minutes, 8-9 10 minutes and so on). Thats my current queue with my timemeasure Is there a way to do so?
]
Create a normal dataset and call it datasetHourly. Deactivate the option Use time as horizontal value. This is where we will store your hourly data.
Creat a cyclic event and set the trigger to cyclic, once every hour.
This cyclic event will get the current mean of your time measurement ( waiting time + service time in your example) and save this single value in the extra dataset.
Also we have to clear the dataset that is integrated into the timeMeasurementEnd, in order to get clean statistics again for the next hour interval.
datasetHourly.add(time(HOUR),timeMeasureEnd.dataset.getYMean());
timeMeasureEnd.dataset.reset();
You can now visualise the hourly development by adding the hourlyDataset to a normal plot.

Detect an application that has not sent a message in the last 15 minutes using Kapacitor

We are writing a message count per application to InfluxDb every 10 seconds. I want to be able to generate an alert if that number has not changed in the last 15 minutes.
I tried derivative, but that gives the change for each data point. The unit parameter just scales the result. Derivative works well for our chattier apps where we can check if a message was sent every 10s, but the 15 minute window is not working.
I tried using spread with a batched query grouped by time, but that gives me the change in whole quarters of the hour (00 to 15, 15:01 to 30, 30:01 to 45...). I want to be able to check the last 15 minutes and check it every minute or so.
I tried using a windowed stream with spread, but it seems to be grabbing points outside the window since it is giving a non-zero answer.

Matlab: run program until condition is met

I'm currently modelling the dynamics of an ice sheet. I therefore made a script that plots the volume of an ice sheet throughout time (in steps of 500 years). The volume increases rapidly at first, but the curve flattens later on as the volume does not change anymore and the ice sheet is in steady state... its shape is familiar like y=ln(x)... I thus have 2 output arrays, namely a) vol_time with the time in steps of 500 years and b) vol with the corresponding volume. Now, the program runs until a fixed time that I inserted (200 000 years) but I want to run the program only until this steady state is reached. So my question is: how can I make the program run only until the volume changes with only 0.002% per 500 years?
Thanks
You can ether wrap your ice-sheet thickness calculation in a while loop so the code performs the calculation until the 0.0002% condition is met or you loop through the whole 200.000 years.
Another option could be to add a if check end the end of your ice-sheet thickness calculation and if you enter and then add break in the if, this way the loop terminate.

Scope displays unexpected puls generator output

I am having troubles understanding the output of my scope in this simple simulink model:
I am using a fixed step solver (tried with ode3 and ode8).
Pulse type of the puls generator is set to Sample based and I varied the Period and Pulse Width.
First I set the simulation time to 10 and set the puls generator to Period = 10 and Puls width = 5. The output of the scope is as expected:
But when I tried with simulation time 10,000 and the puls generator with Period = 1,000 and Puls width = 500 it seems my scope is wrong:
Why is the first falling edge at 5,500? I used the Autoscale button every time.
Using sim time 100,000 and Period = 10,000 and Puls width = 5,000 I don't even get a single falling edge:
Even with longer simulation time there seems to be a single rising edge at the end of the scope window.
What am I doing wrong? Is the scope not suitable for such long simulation times using fixed step solver? Or is it not "safe" to use the Autoscale button?
All of the plots you show are correct. Simulink is fine with long simulation times. It is "safe" to use the Autoscale button.
By default a scope is set to only display the last 5000 simulation time steps. Since your model is taking a step size of 1s (this is based on using the default step size of the Pulse Generator, which is 1s), in your second plot you are only seeing points from t=5000 to t=10000 (so the first down step in that time period is at 5500), and in your third plot you are only seeing points from t=95000 to t=100000 (which is a period in which the value of the pulse is low/zero).
To see all simulation times, open the Scope block's parameters (by clicking the button with a picture of a cog on it), go to the History tab, and deselect the Limit data points to last: check box.
Then rerun your simulation and press the autoscale button. You'll then see what (I think) you are expecting.