Pine script enter and exit positions, alert problems - alerts

The problem is when the strategy is going long or short, Tradingview sends the alert
e=oandapractice s=US SPX 500 q=1 b=long t=market or
e=oandapractice s=US SPX 500 q=1 b=short t=market
but also at the same moment it sends:
e=oandapractice s=US SPX 500 c=position t=market
What I want is that when the strategy is going long or short, Tradingview only sends the first alert:
e=oandapractice s=US SPX 500 q=1 b=long t=market or
e=oandapractice s=US SPX 500 q=1 b=short t=market
when the position is stopped by a loss or profit, Tradingview must send only the following alert:
e=oandapractice s=US SPX 500 c=position t=market
See here the part of my script;
//LONG POSITION
if inTradeWindow and GoLong
strategy.entry("Enter Long", strategy.long, comment="Daan gaat LONG")
alert("e=oandapractice s=US SPX 500 q=1 b=long t=market", alert.freq_once_per_bar),
strategy.exit("Exit Long", from_entry="Enter Long", loss = 40, profit = 60),
alert("e=oandapractice s=US SPX 500 c=position t=market", alert.freq_once_per_bar)
//SHORT POSITION
if inTradeWindow and GoShort
strategy.entry("Enter Short", strategy.short, comment="Daan gaat SHORT"),
alert("e=oandapractice s=US SPX 500 q=1 b=short t=market", alert.freq_once_per_bar),
strategy.exit("Exit Short", from_entry="Enter Short", loss = 40, profit = 60),
alert("e=oandapractice s=US SPX 500 c=position t=market", alert.freq_once_per_bar)
I would like that Tradingview only sends the alert e=oandapractice s=US SPX 500 c=position t=market when the strategy hit the loss or profit from the strategy.exit

Related

How to capture windows 10/windows 11 advanced display settings for multiple monitors

I am trying to capture the following displays information connected to my laptop programatically using powershell but I am unable to find a way. This information can be found via the windows GUI at Settings > Display > Advanced Display Information (2 screenshots attached below).
Here's the information I am trying to capture
Display Name: (In this case, display name for internal would be but the external one would be "ASUS VP 228)
Display Resolution: 1680x1050 and 1920x1080 for the 2 displays
Whether it's an internal/external display: True and False
Refresh rate: 60Hz and 60Hz
Here's what I've tried
Get-WmiObject win32_videocontroller
Returns the resolution under parameter VideoModeDescription but even then, it seems to return the value of "Active Signal Resolution" (from the screenshot) below).
Get-WmiObject Win32_Desktopmonitor
DeviceID : DesktopMonitor1
DisplayType :
MonitorManufacturer : (Standard monitor types)
Name : Generic PnP Monitor
ScreenHeight :
ScreenWidth :
Only get output information for 1 out of the 2 monitors and don't get ScreenHeight or ScreenWidth` values.
get-ciminstance -namespace root\wmi -classname wmimonitorbasicdisplayparams
Active : True
DisplayTransferCharacteristic : 120
InstanceName : DISPLAY\IVO8C66\5&462698&0&UID256_0
MaxHorizontalImageSize : 31
MaxVerticalImageSize : 17
SupportedDisplayFeatures : WmiMonitorSupportedDisplayFeatures
VideoInputType : 1
PSComputerName :
Active : True
DisplayTransferCharacteristic : 120
InstanceName : DISPLAY\ACI22C3\5&462698&0&UID265_0
MaxHorizontalImageSize : 48
MaxVerticalImageSize : 27
SupportedDisplayFeatures : WmiMonitorSupportedDisplayFeatures
VideoInputType : 1
PSComputerName
Gives me the correct monitor count but doesn't give me any other information.
I then tried using the DumpEDID tool and it gave me more information but didn't give me current monitor resolution or whether it's an internal display or not.
DumpEDID v1.07
Copyright (c) 2006 - 2018 Nir Sofer
Web site: http://www.nirsoft.net
*****************************************************************
Active : Yes
Registry Key : DISPLAY\ACI22C3\5&462698&0&UID265
Monitor Name : ASUS VP228
Serial Number : G6LMTF155938
Manufacture Week : 26 / 2016
ManufacturerID : 26884 (0x6904)
ProductID : 8899 (0x22C3)
Serial Number (Numeric) : 155938 (0x00026122)
EDID Version : 1.3
Display Gamma : 2.20
Vertical Frequency : 50 - 75 Hz
Horizontal Frequency : 24 - 83 KHz
Maximum Image Size : 48 X 27 cm (21.7 Inch)
Maximum Resolution : 1920 X 1080
Support Standby Mode : No
Support Suspend Mode : No
Support Low-Power Mode : Yes
Support Default GTF : No
Digital : Yes
Supported Display Modes :
720 X 400 70 Hz
640 X 480 60 Hz
640 X 480 67 Hz
640 X 480 72 Hz
640 X 480 75 Hz
800 X 600 56 Hz
800 X 600 60 Hz
800 X 600 72 Hz
800 X 600 75 Hz
832 X 624 75 Hz
1024 X 768 60 Hz
1024 X 768 70 Hz
1024 X 768 75 Hz
1280 X 720 60 Hz
1152 X 864 75 Hz
1280 X 960 60 Hz
1440 X 900 60 Hz
1280 X 1024 60 Hz
1280 X 1024 75 Hz
1680 X 1050 60 Hz
1920 X 1080 60 Hz
*****************************************************************
*****************************************************************
Active : Yes
Registry Key : DISPLAY\IVO8C66\5&462698&0&UID256
Manufacture Week : 0 / 2019
ManufacturerID : 53030 (0xCF26)
ProductID : 35942 (0x8C66)
Serial Number (Numeric) : 0 (0x00000000)
EDID Version : 1.4
Display Gamma : 2.20
Maximum Image Size : 31 X 17 cm (13.9 Inch)
Maximum Resolution : 1920 X 1080
Support Standby Mode : No
Support Suspend Mode : No
Support Low-Power Mode : No
Support Default GTF : No
Digital : Yes
Supported Display Modes :
1920 X 1080 60 Hz
The script here gives me almost what I want except it doesn't give me the monitor name nor does it give me information whether it's internal or not.
I have attached 2 screenshots from the Settings > Display > Advanced Display page which is the information I am looking to capture.

Unable to Determine why Frame Too Large For GIF Govips

I am trying to resize the following GIF
Original Dimensions are: 1270 x 1270 and a total of 149 Pages
I am resizing to the following Dimensions:
250 x 250 (Successful)
500 x 500 (Successful)
750 x 750 (Unsuccessful)
It fails for the last case and after some digging I found that the limits are set in libvips. I am not able to conclude how the dimensions are violating the constraints.
Constraints Being:
if( (guint64) frame_rect.width * frame_rect.height > INT_MAX / 4 ||
frame_rect.width > 65535 ||
frame_rect.height > 65535 ) {
vips_error( class->nickname, "%s", _( "frame too large" ) );
return( -1 );
}
Currently I have the latest govips(v2.11.0) and vips(8.13.3) versions installed.
I tried different sizes and it is working till 740 x 740. I tried to change the Export Params but am unable to figure the math behind why the frame is too large.

Movement algorithm with friction

For example, I have an object that follows mouse horizontally, its minimum position is 100 and the maximum is 200.
Within this range, it follows mouse linearly, meaning 1 unit of mouse position equals to 1 unit of object position.
Now, if the mouse is outside of the range (below 100, or above 200), I want it to start applying friction, so the object gracefully stops the further it is from range, for example:
Mouse position | Object position
200 200
220 205
240 209
260 212
280 215
300 217
320 218
340 219
360 220
380 220
400 220
...
I managed to implement it like this within mouse-move handler:
if (mousePosition > 200 || mousePosition < 100) {
delta = mousePosition - objectPosition;
objectPosition += delta * 0.25; // 0.25 if friction factor
}
But is there a better way? How to implement function outside of mouse-move handler:
getObjectPosition(mousePosition) {
return // ???
}
The question is language agnostic.
You can calculate your the object position as a piecewise function of the mouse position:
getObjectPosition(mousePosition) {
if(mousePosition < 100)
return 100 - friction(100 - mousePosition);
if(mousePosition > 200)
return 200 + friction(mousePosition - 200);
return mousePosition;
}
Where friction is a function to calculate the "soft" function you want. A simple one would be:
friction(x) {
return 0.25*x;
}
which would reduce the object speed by 0.25 when its beyond the [100, 200] bounds. Your function seems to approach some kind of asymptote though. You can achieve it with, for example, a quadratic:
friction(x) {
M = 160;
x = min(x, M);
return x*(1 - x/(2*M));
}
Here the object will gradually slow down, and stop completely when the mouse is outside the [-60, 360] interval.

CGDisplayModeGetWidth/Height() sometimes returns pixels, sometimes points

According to Apple, both CGDisplayModeGetWidth() and CGDisplayModeGetHeight() should return points instead of pixels starting in macOS 10.8. But Apple's word on those APIs isn't consistent because here they say that the functions return pixels and not points.
This confusion is also reflected in practice because both functions only seem to return points sometimes, not all the time. Sometimes they also return pixels. Consider this example:
CGDirectDisplayID id = CGMainDisplayID();
CFArrayRef modes = CGDisplayCopyAllDisplayModes(id, NULL);
CGDisplayModeRef mode;
int c = 0, k, n;
n = CFArrayGetCount(modes);
for(k = 0; k < n; k++) {
mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, k);
printf("GOT SIZE: %d %d\n", (int) CGDisplayModeGetWidth(mode), (int) CGDisplayModeGetHeight(mode));
}
CFRelease(modes);
The code iterates over all available screen modes. In this example, the output is in pixels.
When using this code, however, the output is in points:
CGDirectDisplayID id = CGMainDisplayID();
mode = CGDisplayCopyDisplayMode(id);
printf("NEW GOT SIZE: %d %d\n", (int) CGDisplayModeGetWidth(mode), (int) CGDisplayModeGetHeight(mode));
CGDisplayModeRelease(mode);
But why? Why do CGDisplayModeGetWidth() and CGDisplayModeGetHeight() return pixels in the first code snippet and points in the second? This is confusing me.
To make things even more complicated, starting with macOS 10.8 there are two new APIs, namely CGDisplayModeGetPixelWidth() and CGDisplayModeGetPixelHeight(). These always return pixels, but I still don't understand why CGDisplayModeGetWidth() and CGDisplayModeGetHeight() return pixels in the first code snippet above... is this a bug?
EDIT
Here is the output for my 1680x1050 monitor. I am using Quartz Debug to put the monitor in 840x525 screen mode to do Retina tests. You can see that the output of the first code snippet must be in pixels because it returns modes such as 1680x1050 which would correspond to 3360x2100 pixels if it were points. Another proof that the first code snippet returns pixels not points lies in the fact that the screen mode the monitor is currently in (i.e. 840x525) isn't returned at all. Only the second code snippet returns this mode.
GOT SIZE: 1680 1050
GOT SIZE: 1152 870
GOT SIZE: 1280 1024
GOT SIZE: 1024 768
GOT SIZE: 1024 768
GOT SIZE: 1024 768
GOT SIZE: 832 624
GOT SIZE: 800 600
GOT SIZE: 800 600
GOT SIZE: 800 600
GOT SIZE: 800 600
GOT SIZE: 640 480
GOT SIZE: 640 480
GOT SIZE: 640 480
GOT SIZE: 640 480
GOT SIZE: 1280 1024
GOT SIZE: 1280 960
GOT SIZE: 848 480
GOT SIZE: 1280 960
GOT SIZE: 1360 768
GOT SIZE: 800 500
GOT SIZE: 1024 640
GOT SIZE: 1280 800
GOT SIZE: 1344 1008
GOT SIZE: 1344 840
GOT SIZE: 1600 1000
--------------------------
NEW GOT SIZE: 840 525

SVG animate point in cycle

I have a path with various arcs. I want to animate just a single arc indefinitely. Currently, what I can do is this :
http://jsfiddle.net/gLxkt/1/
<animate id="c1" xlink:href="#p1" attributeName="d" attributeType="XML"
from="M 300 300 C 300 300 600 300 300 400 "
to="M 300 300 C 300 300 400 300 300 400 " dur="1s" fill="freeze" />
<animate id="c2" begin="c1.end" xlink:href="#p1" attributeName="d" attributeType="XML"
from="M 300 300 C 300 300 400 300 300 400 "
to="M 300 300 C 300 300 600 300 300 400 " dur="1s" fill="freeze" />
Which can do this once. How can I make the animation indefinite?
The end="indefinite" makes it repeat and the begin makes it start both at 0s and when the other animation finishes. Continuously repeats in Firefox.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%"
>
<path id="p1" d="M 300 300 C 300 300 600 300 300 400 " stroke="blue" fill="none" stroke-width="4" />
<g>
<path id="p1" d="M 300 300 C 300 300 600 300 300 400 " stroke="blue" fill="none" stroke-width="4" />
<animate id="c1" begin="c2.end; 0s" end="indefinite" xlink:href="#p1" attributeName="d" attributeType="XML"
from="M 300 300 C 300 300 600 300 300 400 "
to="M 300 300 C 300 300 400 300 300 400 " dur="1s" fill="freeze" />
<animate id="c2" begin="c1.end" end="indefinite" xlink:href="#p1" attributeName="d" attributeType="XML"
from="M 300 300 C 300 300 400 300 300 400 "
to="M 300 300 C 300 300 600 300 300 400 " dur="1s" fill="freeze" />
</g>
</svg>
An easy way is to use the "values" array - which works in Chrome, Firefox & Safari (and I presume Opera) but not IE which has no support for SMIL anyway (although there's a polyfill library somewhere). But Robert's answer is clearly more elegant.
<animate id="c1" xlink:href="#p1" attributeName="d" attributeType="XML"
values="M 300 300 C 300 300 600 300 300 400;M 300 300 C 300 300 400 300 300 400;M 300 300 C 300 300 600 300 300 400" dur="2s" repeatCount="indefinite" fill="freeze" />
http://jsfiddle.net/gLxkt/2/

Resources