Trading_commands

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Re: Trading_commands

Postby 7000306337 » Mon Oct 23, 2017 7:11 pm

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 ?
7000306337
 
Posts: 26
Joined: Sat Jul 15, 2017 9:48 am

Re: Trading_commands

Postby Apprentice » Tue Oct 24, 2017 4:02 am

Sure, if you use core.host:execute("getSyncHistory" do get your price data.
This is the case with most MTF MCP indicators.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19800
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trading_commands

Postby 7000306337 » Tue Nov 21, 2017 10:42 am

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,
7000306337
 
Posts: 26
Joined: Sat Jul 15, 2017 9:48 am

Re: Trading_commands

Postby Apprentice » Wed Nov 22, 2017 5:14 am

Sure. Strategy can trade on different currency pairs.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19800
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trading_commands

Postby SirOrigami » Thu Nov 30, 2017 6:53 pm

Yeah, Move stop to breakeven +x pips would be awesome
SirOrigami
 
Posts: 7
Joined: Fri Nov 24, 2017 2:48 pm

Re: Trading_commands

Postby Apprentice » Sat Dec 02, 2017 5:51 am

Your request is added to the development list under Id Number 3967
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19800
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trading_commands

Postby Apprentice » Wed Dec 13, 2017 10:28 am

Try this version.
Trading_commands.lua
(14.88 KiB) Downloaded 235 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19800
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trading_commands

Postby 7000306337 » Thu Jan 11, 2018 10:19 am

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,
7000306337
 
Posts: 26
Joined: Sat Jul 15, 2017 9:48 am

Re: Trading_commands

Postby Apprentice » Fri Jan 12, 2018 6:46 am

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.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19800
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Trading_commands

Postby 7000306337 » Fri Jan 12, 2018 10:24 am

-- 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
7000306337
 
Posts: 26
Joined: Sat Jul 15, 2017 9:48 am

PreviousNext

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 30 guests