Connecting Amibroker with Tradetron is done through API calls
So what are API calls?
You can set your own variables in Tradetron by sending requests.
These requests are sent as URL https requests (one way)
The process is the same, irrespective of the platform.
The Url request is tagged with a unique token id [which you will have to procure from us] and is limited to one single strategy.
The URL call, along with the unique token also carries the variable name and its value.
This request is then updated in the tradetron database
Once the variable is updated, in your tradetron strategy, you can use Get Runtime keyword to fetch the value.
If the fetched value matches the condition a trade will be fired from Tradetron.
Tradetron strategy, when running, keeps checking for the update in the variable. So when the update happens, an action related to that value will be triggered.
Let us understand this with an example.
Assume that you are going long on Nifty 50 index future when
- Instrument: Nifty 50 Index Future
- Lots: 1
- Buy: Close crosses EMA(20) from bottom to top
- Sell: Close cross EMA(20) from top to bottom
- Short: Close cross EMA(20) from top to bottom [Reverse trade]
- Cover: Close crosses EMA(20) from bottom to top
Buy = Cross(C,EMA(C,20));Sell = Cross(EMA(C,20),C);Short = Cross(EMA(C,20),C);Cover = Cross(C,EMA(C,20));TradeActive=1;_SECTION_BEGIN("TTron");EnableScript("VBScript");<%Public Sub callurl(varname,val)Dim oXMLHTTPDim oStreamSet oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP")token="50fe9da2-jnfv-436e-9072-65cfdbc7da85"url = "https://api.tradetron.tech/api?auth-token="+token+"&key="+varname+"&value="+valoXMLHTTP.Open "GET", url, FalseoXMLHTTP.setRequestHeader "Cache-Control", "no-cache"oXMLHTTP.setRequestHeader "Pragma", "no-cache"oXMLHTTP.SendEnd Sub%>pb = GetScriptObject();signalBuy = Buy[BarCount-1]>0;signalSell = Sell[BarCount-1]>0;signalShort = Short[BarCount-1]>0;signalCover = Cover[BarCount-1]>0;if(TradeActive){if (signalSell==true AND StaticVarGet("NIFTY"+"sell")==0 ){pb.callurl("NIFTY","2");StaticVarSet("NIFTY"+"sell",1);}else if (signalSell != True){ StaticVarSet("NIFTY"+"sell",0);}if (signalCover==true AND StaticVarGet("NIFTY"+"cover")==0 ){pb.callurl("NIFTY","4");StaticVarSet("NIFTY"+"cover",1);}else if (signalCover != True){ StaticVarSet("NIFTY"+"cover",0);}if (signalBuy==True AND StaticVarGet("NIFTY"+"buy")==0 ){pb.callurl("NIFTY","1");StaticVarSet("NIFTY"+"buy",1);}else if (signalBuy != True){ StaticVarSet("NIFTY"+"buy",0);}if (signalShort==True AND StaticVarGet("NIFTY"+"short")==0 ){pb.callurl("NIFTY","3");StaticVarSet("NIFTY"+"short",1);}else if (signalShort != True){ StaticVarSet("NIFTY"+"short",0);} }//end main if_SECTION_END();
This code will:
- Set variable, "NIFTY" to 1 and 4 when close crosses EMA(20) upwards.
- Set variable, "NIFTY" to 2 and 3 when close crosses EMA(20) downwards
Now in Tradetron, you can you create two sets,
Set 1 for Long Entry and Long Exit & Set 2 for Short Entry and Short Exit
Each condition builder, you will use Get Runtime Keyword to check the value
You will mention your appropriate positions in the positioning builder
Now when your AFL code runs and a condition is satisfied, it will trigger a URL request to tradetron
Tradetron will then check if the value of the variable matches and then fires the trade accordingly.
You can duplicate the strategy for your reference from here
Note: This Strategy is only for your reference and will not work once duplicated into your account You will have to generate unique token for your template and map it in your AFL code for it to work.
If you have any queries, please free to write to us at [email protected]