Tradingview strategy issues when calc_on_order_fills, calc_on_every_tick, and process_orders_on_close are true - calculation

I'm trying to figure out how to prevent the multiple entries that happen when
calc_on_order_fills= true, calc_on_every_tick= true, process_orders_on_close= true
and the target is hit in the same candle.
After the entry fill, and although I have barstate.isconfirmed for entering position (e.g. if long_Condition and barstate.isconfirmed) if the target or stop is hit in the same candle, the backtester records, 2nd, 3rd and ... attempts
I've used combinations of barstate.isconfirmed and barstate.isnew for entry conditions but there still is the same problem (see the image)
Does anyone have a solution to prevent this behavior?

Related

How to make a keybind work unconditionally in mpv?

The keys 9 and 0 are, by default, volume- and volume+, respectively.
I often use this stats screen to check filenames and such:
Unfortunately, if I try to increase the volume too quickly after checking the filename, 0 instead changes the stats page to an unhelpful "Internal performance info" screen that looks like this until quitting mpv:
How can I remove this behaviour from the 0 key and make it always act as volume+ instead?
By re- or unbinding all offending (also script-specific) key binds.
While the stats script is active, its key bindings override any existing ones, but those can be changed or removed.
You can add the option key_page_0=key to script-opts/stats.conf in an mpv configuration location such as the following file:
# ~/.config/mpv/script-opts/stats.conf
key_page_0=5
# to disable instead: key_page_0=
Unlike most configuration, this file is NOT cumulative with itself across locations. (everything from /etc/mpv/script-opts/stats.conf is ignored instead of added to if you also have ~/.config/mpv/script-opts/stats.conf)
Or append stats-key_page_0=key to the script-opts list,
such as, to unbind:
mpv --script-opts-append=stats-key_page_0=
or in an mpv.conf file:
# ~/.config/mpv/mpv.conf
script-opts-append=stats-key_page_0=
# to change instead: script-opts-append=stats-key_page_0=5
In the meantime:
You can revert the page back to "Show usual stats" by pressing 1 while shown instead of restarting mpv.
From the mpv manual:
While the stats are visible on screen the following key bindings are
active, regardless of existing bindings. They allow you to switch
between pages of stats:
1 Show usual stats
2 Show frame timings (scroll)
3 Input cache stats
4 Active key bindings (scroll)
0 Internal stuff (scroll)

Boolean preferences problem in Corona Simulator

I'm working on a mobile app using Corona SDK and trying to save settings using system.setPreferences()/system.getPreference() functions. On my android phone it works fine, but in Corona Simulator it works in the following way:
First time, I run the following code:
system.setPreferences("app", {
test = true
})
print(system.getPreference("app", "test", "boolean"))
It prints true, as expected
Second time, I try to get preference without saving it (it should have been already saved in previous step)
print(system.getPreference("app", "test", "boolean"))
Output is the following:
ERROR: C:\Users\kezzyhko\Desktop\MobileGame\main.lua:7: system.getPreference() - Preference's string value cannot be converted to boolean.
nil
Trying to get it as string
print(system.getPreference("app", "test", "string"))
I get 1
I tried too look into C:\Users\kezzyhko\AppData\Local\Corona Labs\Corona Simulator\Sandbox\mobilegame-370DE4D889B5BBC98141FE51641482AD\.system\CoronaPreferences.sqlite file, where preferences are actually stored, and indeed boolean values are saved as 0/1. If in this database I manually edit them to true, the code starts working as expected:
print(system.getPreference("app", "test", "boolean"))
outputs true
Is it a known issue (I could not find any info about it)? Is there a way to fix it without dirty workarounds?
That sounds like a technicality. Sure, they are "boolean" in that they are 1s and 0s, but since they are stored in a file, they are probably stored as text, i.e. strings.
So when you load the data, you probably need to always take them in as strings and then manually say that 0 is false and 1 is true.
I'd recommend saving your data using JSON/SQL. Here's a simple tutorial for JSON: https://docs.coronalabs.com/tutorial/data/jsonSaveLoad/index.html

Lua script in FreeSWITCH exits bridge immediately when bypass_media = true

How do I make the script wait for the bridge to terminate before continuing when I have "bypass_media" set to true?
This snippet -
freeswitch.consoleLog("err","session before="..tostring(session:ready()).."\n")
session:execute("set","bypass_media=true")
session:execute("bridge","sofia/gateway/carrierb/12345678")
freeswitch.consoleLog("err","session after="..tostring(session:ready()).."\n")
from an audio perspective, it works perfectly with bridge_media set to either true or false, and a wireshark trace shows the audio either passing through (false) or end to end (true).
But with bypass set to true, the script continues without pausing, and the session is no longer ready (session:ready() == false).
The channel seems to go into a hibernate state, but I have housekeeping to do after the bridge is finished which I simply cannot do.
Same happens if i do the bridge in XML dialplan, immediately carries on causing my housekeeping to fire early.
FreeSWITCH (Version 1.6.20 git 43a9feb 2018-05-07 18:56:11Z 64bit)
Lua 5.2
EDIT 1 -
I can get "api_hangup_hook=lua housekeeping.lua" to work, but then I have to pass tons of variables and it fires up a new process/thread/whatever, which seems a little overkill unless that's the only way.
I have a workaround, but would still like an answer to the question if anyone has one (ie how to stop the bridge exiting immediately).
If I set this before the bridge :
session:execute("set","bypass_media=true")
session:execute("set","session_in_hangup_hook=true")
session:execute("set","api_hangup_hook=lua housekeeping.lua "..<vars>)
then "housekeeping.lua" fires when the bridge actually terminates (which is long after the script does).
In housekeeping.lua I can then do :
session:getVariable("billmsec")
and it seems to have the correct values in them, allowing me to do my housekeeping.
My problem with this is the uncertainty of playing with variables from a session that appears to have gone away from a script that fires at some point in the future.
Anyway, it'll have to do until I can find out how to keep control inside the original script.

Can Dataflow sideInput be updated per window by reading a gcs bucket?

I’m currently creating a PCollectionView by reading filtering information from a gcs bucket and passing it as side input to different stages of my pipeline in order to filter the output. If the file in the gcs bucket changes, I want the currently running pipeline to use this new filter info. Is there a way to update this PCollectionView on each new window of data if my filter changes? I thought I could do it in a startBundle but I can’t figure out how or if it’s possible. Could you give an example if it is possible.
PCollectionView<Map<String, TagObject>>
tagMapView =
pipeline.apply(TextIO.Read.named("TagListTextRead")
.from("gs://tag-list-bucket/tag-list.json"))
.apply(ParDo.named("TagsToTagMap").of(new Tags.BuildTagListMapFn()))
.apply("MakeTagMapView", View.asSingleton());
PCollection<String>
windowedData =
pipeline.apply(PubsubIO.Read.topic("myTopic"))
.apply(Window.<String>into(
SlidingWindows.of(Duration.standardMinutes(15))
.every(Duration.standardSeconds(31))));
PCollection<MY_DATA>
lineData = windowedData
.apply(ParDo.named("ExtractJsonObject")
.withSideInputs(tagMapView)
.of(new ExtractJsonObjectFn()));
You probably want something like "use an at most a 1-minute-old version of the filter as a side input" (since in theory the file can change frequently, unpredictably, and independently from your pipeline - so there's no way really to completely synchronize changes of the file with the behavior of the pipeline).
Here's a (granted, rather clumsy) solution I was able to come up with. It relies on the fact that side inputs are implicitly also keyed by window. In this solution we're going to create a side input windowed into 1-minute fixed windows, where each window will contain a single value of the tag map, derived from the filter file as-of some moment inside that window.
PCollection<Long> ticks = p
// Produce 1 "tick" per second
.apply(CountingInput.unbounded().withRate(1, Duration.standardSeconds(1)))
// Window the ticks into 1-minute windows
.apply(Window.into(FixedWindows.of(Duration.standardMinutes(1))))
// Use an arbitrary per-window combiner to reduce to 1 element per window
.apply(Count.globally());
// Produce a collection of tag maps, 1 per each 1-minute window
PCollectionView<TagMap> tagMapView = ticks
.apply(MapElements.via((Long ignored) -> {
... manually read the json file as a TagMap ...
}))
.apply(View.asSingleton());
This pattern (joining against slowly changing external data as a side input) is coming up repeatedly, and the solution I'm proposing here is far from perfect, I wish we had better support for this in the programming model. I've filed a BEAM JIRA issue to track this.

Conditional OCR rotation on the image or Page in KOFAX

We have two source of inputs to create a Batch first is Folder Import and second is Email import.
I need to add condition where if the source of image is Email it should not allow to rotate the image and like wise if source if Folder import it should rotate the image.
I have added a script for this in KTM.
It is showing proper message of the source of image but it is not stopping the rotation of the image.
Below check the below script for reference.
Public Function setRotationRule(ByVal pXDoc As CASCADELib.CscXDocument) As String
Dim i As Integer
Dim FullPath As String
Dim PathArry() As String
Dim xfolder As CscXFolder
Set xfolder = pXDoc.ParentFolder
While Not xfolder.IsRootFolder
Set xfolder = xfolder.ParentFolder
Wend
'Added for KTM script testing
FullPath= "F:\Emailmport\dilipnikam#gmail.com_09-01-2014_10-02-37\dfdsg.pdf"'
If xfolder.XValues.ItemExists("AC_FIELD_OriginalFileName") Then
FullPath= xfolder.XValues.ItemByName("AC_FIELD_OriginalFileName").Value
End If
PathArry() = Split(FullPath,"\")
MsgBox(PathArry(1))
If Not PathArry(1) = "EmailImport" Then
For i = 0 To pXDoc.CDoc.Pages.Count - 1
pXDoc.CDoc.Pages(i).Rotation = Csc_RT_NoRotation
Next i
End If
End Function
The KTM Scripting Help has a misleading topic named "Dynamically Suppress Orientation Detection for Full Page OCR" where it shows setting Csc_RT_NoRotation from the Document_AfterClassifyXDoc event.
The reason I think this is misleading is because rotation may already have occurred before that event and thus setting the property has no effect. This can happen if layout classification has run, or if OCR has run (which can be triggered by content classification, or if any project-level locators need OCR). The sample in that topic does suggest that it is only for use when classifiers are not used, but it could be explained better.
The code you've shown would be best called from the event Document_BeforeProcessXDoc. This will run before the entire classify phase (including project-level locators), ensuring that rotation could not have already occurred.
Of course, also make sure this isn't because of a typo or anything else preventing the code from actually executing, as mentioned in the comments.

Resources