Page 4 of 8
Re: Trading_commands
Posted:
Mon Oct 23, 2017 7:11 pm
by 7000306337
Thank you very much in advance for your awesome mentor,
In STRATEGIES
local tk, H0
function ExtUpdate(id, source, period)
if id==tickSourceID then tk = source[period] end
if id==barSourceID then H0 = source.high[period] end
-- now every tick we can compare tick price with bar.high price.
end
Is there an equivalent way In INDICATORS to compare tick price with bar prices ?
Re: Trading_commands
Posted:
Tue Oct 24, 2017 4:02 am
by Apprentice
Sure, if you use core.host:execute("getSyncHistory" do get your price data.
This is the case with most MTF MCP indicators.
Re: Trading_commands
Posted:
Tue Nov 21, 2017 10:42 am
by 7000306337
Thank you very much in advance for your awesome mentor.
Is it possible to have a STRATEGY or an INDICATOR applied to MULTIPLE instruments?
(To eliminate having multiple instances of the same STRATEGY or INDICATOR applied to each instrument)
Much appreciated,
Re: Trading_commands
Posted:
Wed Nov 22, 2017 5:14 am
by Apprentice
Sure. Strategy can trade on different currency pairs.
Re: Trading_commands
Posted:
Thu Nov 30, 2017 6:53 pm
by SirOrigami
Yeah, Move stop to breakeven +x pips would be awesome
Re: Trading_commands
Posted:
Sat Dec 02, 2017 5:51 am
by Apprentice
Your request is added to the development list under Id Number 3967
Re: Trading_commands
Posted:
Wed Dec 13, 2017 10:28 am
by Apprentice
Re: Trading_commands
Posted:
Thu Jan 11, 2018 10:19 am
by 7000306337
Thank you very much in advance for your awesome mentor.
Follow up to my previous enquiry to have one single STRATEGY or INDICATOR applied to MULTIPLE instruments? (To eliminate having multiple instances of the same STRATEGY or INDICATOR applied to each instrument)
For example I can implement a STRATEGY or an INDICATOR to EXIT positions of a specific instrument when its RSI indicator reaches a certain level.
But don`t know how to apply it to ALL instruments without having multiple instances of the same (one for each instrument)
Much appreciated,
Re: Trading_commands
Posted:
Fri Jan 12, 2018 6:46 am
by Apprentice
But don`t know how to apply it to ALL instruments without having multiple instances of the same (one for each instrument)
Give me an example.
Will write this for you.
Re: Trading_commands
Posted:
Fri Jan 12, 2018 10:24 am
by 7000306337
-- Appling this indicator to to EUR/USD chart will exit EUR/USD long pos if EUR/USD avg[period] crosses below threshold
-- and will exit EUR/USD short pos if EUR/USD avg[period] crosses above threshold.
-- I wish to modify it to work also on an additional another instument say USD/JPY.
-- I mean (I could) but do not want to have another instance applied it to a separate USD/JPY chart.
-- Wish to have ONLY ONE instance to exit both EUR/USD and USD/JPY.
- Code: Select all
function Init()
indicator:name("avg");
indicator:description("Khairy N");
-- indicator:requiredSource(core.Tick);
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
-- indicator:type(core.Indicator);
-- indicator:setTag("group", "Classic Oscillators");
indicator:setTag("group", "Moving Averages");
indicator.parameters:addGroup("Calculation");
indicator.parameters:addInteger("nn", "nn", "nn", 22, 1, 1000000);
indicator.parameters:addInteger("pos", "pos", "pos", 1, -1, 1);
indicator.parameters:addDouble("thrsh", "thrsh", "thrsh", 1.23, 0.1, 1000);
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("clravg", "clravg", "clravg", core.rgb(255, 0, 255));
indicator.parameters:addInteger("widthavg", "widthavg", "widthavg", 1, 1, 5);
indicator.parameters:addInteger("styleavg", "styleavg", "styleavg", core.LINE_SOLID);
indicator.parameters:setFlag("styleavg", core.FLAG_LINE_STYLE);
indicator.parameters:addString("Account", "Account2Trade", "", "");
indicator.parameters:setFlag("Account", core.FLAG_ACCOUNT);
end
local nn, Account, Offer, thrsh, pos
local first;
local source = nil;
local avg = nil;
local ColorMode, UPclr, DNclr;
local psz;
local fst=false
function Prepare()
pos = 0 -- position =1 long =-1 short =0 flat
fst=true
nn = instance.parameters.nn;
pos = instance.parameters.pos;
thrsh = instance.parameters.thrsh -- thrshold to exit long above or short below
source = instance.source;
first = source:first()
UPclr = core.rgb(255, 0, 0);
DNclr = core.rgb(255, 255, 255);
psz = source:pipSize();
Account = instance.parameters.Account;
Offer = core.host:findTable("offers"):find("Instrument", instance.source:instrument()).OfferID;
local name = profile:id() .. "(" .. source:name() .. ", " .. nn .. ", " .. thrsh .. ")";
instance:name(name);
avg = instance:addStream("avg", core.Line, name, "avg", instance.parameters.clravg, first)
avg:setWidth(instance.parameters.widthavg);
avg:setStyle(instance.parameters.styleavg);
end
function Update(period)
if period>first+nn then
avg[period] = mathex.avg( source.close, period-nn, period)
if avg[period]<thrsh and pos==1 then exit("B") end
if avg[period]>thrsh and pos==-1 then exit("S") end
end
end
function AsyncOperationFinished(cookie, success, message)
end
function exit(BuySell)
local valuemap, success, msg;
if haveTrades(BuySell) then
valuemap = core.valuemap();
if BuySell == "B" then
BuySell = "S";
else
BuySell = "B";
end
valuemap.OrderType = "CM";
valuemap.OfferID = Offer;
valuemap.AcctID = Account;
valuemap.NetQtyFlag = "Y";
valuemap.BuySell = BuySell;
success, msg = terminal:execute(101, valuemap);
if not(success) then
terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "alert_OpenOrderFailed" .. msg, instance.bid:date(instance.bid:size() - 1));
end
end
end
function haveTrades(BuySell)
local enum, row;
local found = false;
enum = core.host:findTable("trades"):enumerator();
row = enum:next();
while (not found) and (row ~= nil) do
if row.AccountID == Account and
row.OfferID == Offer and
(row.BS == BuySell or BuySell == nil) then
found = true;
end
row = enum:next();
end
return found
end